コード例 #1
0
ファイル: Layout.php プロジェクト: sabril-2t/Open-Ad-Server
 /**
  * @see Sppc_Db_Table_Row_Abstract::toString()
  *
  * @return string
  */
 public function toString()
 {
     $data = array('id' => $this->getId(), 'width' => $this->getWidth(), 'height' => $this->getHeight(), 'sizesW' => array($this->getSizeW1(), $this->getSizeW2(), $this->getSizeW3()), 'sizesH' => array($this->getSizeH1(), $this->getSizeH2(), $this->getSizeH3()));
     // zones section:
     $zones = array();
     $select = $this->select();
     $select->order('order');
     foreach ($this->findDependentRowset('Sppc_Site_Layout_ZoneModel', null, $select) as $zone) {
         $zones[] = array('id' => $zone->getId(), 'colspan' => $zone->getColspan(), 'rowspan' => $zone->getRowspan());
     }
     $data['zones'] = $zones;
     $site = $this->findParentRow('Sppc_SiteModel');
     $siteChannelModel = new Sppc_Site_ChannelModel();
     // channels section:
     $channels = array();
     foreach ($this->findDependentRowset('Sppc_Site_Layout_ChannelModel') as $layoutChannel) {
         /*@var $layoutChannel Zend_Db_Table_Row*/
         // Ugly but work:
         $channel = $layoutChannel->findParentRow('Sppc_ChannelModel');
         $select = $siteChannelModel->select();
         $select->where('id_site=?', $site->getId());
         $select->where('id_channel=?', $channel->getId());
         $select->where('status=?', 'active');
         $siteChannelRow = $siteChannelModel->fetchRow($select);
         if (is_null($siteChannelRow)) {
             continue;
         }
         $dimension = $channel->findParentRow('Sppc_DimensionModel');
         $channels[] = array('id' => $channel->getId(), 'title' => $channel->getName(), 'zone' => $layoutChannel->getIdSiteLayoutZone(), 'x' => $layoutChannel->getX(), 'y' => $layoutChannel->getY(), 'width' => $layoutChannel->getWidth(), 'height' => $layoutChannel->getHeight(), 'id_dimension' => $channel->getIdDimension(), 'ad_type' => $channel->getAdType(), 'max_slots_count' => $dimension->getMaxAdSlots());
     }
     $data['channels'] = $channels;
     return json_encode($data);
 }
コード例 #2
0
ファイル: Site.php プロジェクト: sabril-2t/Open-Ad-Server
 /**
  * Insert/update record in DB
  * 
  * @return mixed
  */
 public function save()
 {
     $needUpdateCategories = false;
     $needUpdateChannels = false;
     if (array_key_exists('categories', $this->_modifiedFields) && $this->_modifiedFields['categories'] == true) {
         $needUpdateCategories = true;
     }
     if (array_key_exists('channels', $this->_modifiedFields) && $this->_modifiedFields['channels'] == true) {
         $needUpdateChannels = true;
     }
     $result = parent::save();
     if ($needUpdateCategories) {
         $siteCategoryModel = new Sppc_Site_CategoryModel();
         $siteCategories = $this->findDependentRowset('Sppc_Site_CategoryModel', 'Site');
         $categories = $this->getCategories();
         foreach ($siteCategories as $siteCategory) {
             if (!array_key_exists($siteCategory->getIdCategory(), $categories)) {
                 $siteCategory->delete();
             }
         }
         foreach ($categories as $category) {
             $needToCreate = true;
             foreach ($siteCategories as $siteCategory) {
                 if ($siteCategory->getIdCategory() == $category->getId()) {
                     $needToCreate = false;
                     break;
                 }
             }
             if ($needToCreate) {
                 $data = array('id_site' => $this->getId(), 'id_category' => $category->getId());
                 $row = $siteCategoryModel->createRow($data);
                 $row->save();
             }
         }
     }
     if ($needUpdateChannels) {
         $siteChannelModel = new Sppc_Site_ChannelModel();
         $siteChannels = $this->findDependentRowset('Sppc_Site_Channel', 'Site');
         $channels = $this->getChannels();
         foreach ($siteChannels as $siteChannel) {
             if (!array_key_exists($siteChannel->getIdChannel(), $channels)) {
                 $siteChannel->setStatus('deleted');
                 $siteChannel->save();
             }
         }
         foreach ($channels as $channel) {
             $needToCreate = true;
             foreach ($siteChannels as $siteChannel) {
                 if ($siteChannel->getIdChannel() == $channel->getId()) {
                     $needToCreate = false;
                     break;
                 }
             }
             if ($needToCreate) {
                 $data = array('id_site' => $this->getId(), 'id_channel' => $channel->getId());
                 $row = $siteChannelModel->createRow($data);
                 $row->save();
             }
         }
     }
     return $result;
 }