ultimix
ad_manager_view.php
Go to the documentation of this file.
1 <?php
2 
3  /*
4  * This source code is a part of the Ultimix Project.
5  * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6  * it's own license wich could be found from the corresponding files or sources.
7  * This source code is provided "as is" without any warranties or garanties.
8  *
9  * Have a nice day!
10  *
11  * @url http://ultimix.sorceforge.net
12  *
13  * @author Alexey "gdever" Dodonov
14  */
15 
27 
38  var $Output;
39 
50  var $CachedMultyFS = false;
51  var $String = false;
52 
63  function __construct()
64  {
65  try
66  {
67  $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
68  $this->String = get_package( 'string' , 'last' , __FILE__ );
69 
70  $PageCSS = get_package( 'page::page_css' , 'last' , __FILE__ );
71  $Path = _get_package_relative_path_ex( 'ad::ad_manager::ad_manager_view' , 'last' );
72  $PageCSS->add_stylesheet( "{http_host}/$Path/res/css/ad_manager_view.css" );
73  }
74  catch( Exception $e )
75  {
76  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
77  }
78  }
79 
98  private function get_campaigns_and_banners()
99  {
100  try
101  {
102  $UserAlgorithms = get_package( 'user::user_algorithms' , 'last' , __FILE__ );
103  $AdCampaignAccess = get_package( 'ad::ad_campaign_access' , 'last' , __FILE__ );
104  $AdBannerAccess = get_package( 'ad::ad_banner_access' , 'last' , __FILE__ );
105 
106  $id = $UserAlgorithms->get_id();
107  $Campaigns = $AdCampaignAccess->unsafe_select( "archived = 0 AND creator = $id" );
108 
109  $ids = implode_ex( ',' , $Campaigns , 'id' );
110  $Banners = $AdBannerAccess->unsafe_select( "archived = 0 AND campaign_id IN ( $ids )" );
111 
112  return( array( $Campaigns , $Banners ) );
113  }
114  catch( Exception $e )
115  {
116  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
117  }
118  }
119 
142  private function compile_campaign( $Campaign , &$Banners )
143  {
144  try
145  {
146  $CompanyTemplate = $this->CachedMultyFS->get_template( __FILE__ , 'campaign.tpl' );
147  $CompanyTemplate = $this->String->print_record( $CompanyTemplate , $Campaign );
148 
149  foreach( $Banners as $j => $Banner )
150  {
151  if( $Campaign->id == $Banner->campaign_id )
152  {
153  $Template2 = $this->CachedMultyFS->get_template( __FILE__ , 'banner.tpl' );
154  $Template2 = $this->String->print_record( $Template2 , $Banner );
155  $CompanyTemplate = str_replace( '{banners}' , $Template2.'{banners}' , $CompanyTemplate );
156  }
157  }
158 
159  $this->Output .= $CompanyTemplate;
160  }
161  catch( Exception $e )
162  {
163  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
164  }
165  }
166 
189  function common_view( $Options )
190  {
191  try
192  {
193  list( $Campaigns , $Banners ) = $this->get_campaigns_and_banners();
194 
195  foreach( $Campaigns as $i => $Campaign )
196  {
197  $this->compile_campaign( $Campaign , $Banners );
198  }
199 
200  $Template = $this->CachedMultyFS->get_template( __FILE__ , 'campaigns_list.tpl' );
201 
202  $this->Output = str_replace( '{output}' , $this->Output , $Template );
203  }
204  catch( Exception $e )
205  {
206  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
207  }
208  }
209 
232  function view( $Options )
233  {
234  try
235  {
236  $ContextSet = get_package_object( 'gui::context_set' , 'last' , __FILE__ );
237 
238  $ContextSet->add_context( dirname( __FILE__ ).'/conf/cfcx_ad_manager_view_common_view' );
239 
240  $ContextSet->execute( $Options , $this , __FILE__ );
241 
242  return( $this->Output );
243  }
244  catch( Exception $e )
245  {
246  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
247  }
248  }
249  }
250 
251 ?>