Esempio n. 1
0
 /**
  * @return AM_Model_Db_Element_Data_Resource
  */
 public function setPageBackground()
 {
     $sResource = $this->getDataValue(self::DATA_KEY_RESOURCE);
     $sFileExtension = pathinfo($sResource, PATHINFO_EXTENSION);
     if ($sResource) {
         $oPageBackground = new AM_Model_Db_PageBackground();
         $oPageBackground->id = $this->getElement()->id;
         $oPageBackground->page = $this->getElement()->page;
         $oPageBackground->type = self::TYPE;
         $oPageBackground->filename = self::DATA_KEY_RESOURCE . "." . $sFileExtension;
         $oPageBackground->save();
     }
     return $this;
 }
Esempio n. 2
0
 /**
  * @todo refactoring. We have to get page background by field weight
  * @param boolean $bUpdateBackground
  * @return void
  */
 public function setUpdated($bUpdateBackground = true)
 {
     $oExportHandler = AM_Handler_Locator::getInstance()->getHandler('export');
     /* @var $handler AM_Handler_Export */
     $this->updated = new Zend_Db_Expr('NOW()');
     $this->save();
     $this->getRevision()->updated = new Zend_Db_Expr('NOW()');
     $this->getRevision()->save();
     $this->getIssue()->updated = new Zend_Db_Expr('NOW()');
     $this->getIssue()->save();
     if (!$bUpdateBackground) {
         $oExportHandler->initExportProcess($this->getRevision());
         return;
     }
     $oNotSortedFields = $this->getFields();
     $aFields = array();
     foreach ($oNotSortedFields as $oField) {
         if (!isset(self::$aBackgroundPriority[$oField->getFieldType()->title])) {
             continue;
         }
         $aFields[self::$aBackgroundPriority[$oField->getFieldType()->title]] = $oField;
     }
     ksort($aFields);
     $oField = null;
     $oElement = null;
     $sFileName = null;
     foreach ($aFields as $oFieldItem) {
         $oElements = $this->getElementsByField($oFieldItem);
         if (!count($oElements)) {
             continue;
         }
         foreach ($oElements as $elementsItem) {
             /* @var $elementsItem AM_Model_Db_Element */
             $sFileName = $elementsItem->getResources()->getDataValue(AM_Model_Db_Element_Data_Resource::DATA_KEY_RESOURCE);
             if (!$sFileName) {
                 continue;
             }
             $oField = $oFieldItem;
             $oElement = $elementsItem;
             break;
         }
         if ($oElement && $oField) {
             break;
         }
     }
     if (is_null($oField) || is_null($oElement)) {
         AM_Model_Db_Table_Abstract::factory('page_background')->deleteBy(array('page' => $this->id));
         $oExportHandler->initExportProcess($this->getRevision());
         return;
     }
     $oBackground = $this->getPageBackground();
     if (!is_null($oBackground)) {
         $oBackground->id = $oElement->id;
         $oBackground->filename = AM_Model_Db_Element_Data_Resource::DATA_KEY_RESOURCE . '.' . pathinfo($sFileName, PATHINFO_EXTENSION);
         $oBackground->updated = $oElement->updated;
         $oBackground->setElement($oElement);
     } else {
         $oBackground = new AM_Model_Db_PageBackground();
         $oBackground->id = $oElement->id;
         $oBackground->filename = AM_Model_Db_Element_Data_Resource::DATA_KEY_RESOURCE . '.' . pathinfo($sFileName, PATHINFO_EXTENSION);
         $oBackground->updated = $oElement->updated;
         $oBackground->page = $this->id;
         $oBackground->type = 'element';
         $oBackground->setElement($oElement);
     }
     $oBackground->save();
     $oExportHandler->initExportProcess($this->getRevision());
     return;
 }