예제 #1
0
파일: Pages.php 프로젝트: ktrzos/plethora
 /**
  * ACTION - Particular page.
  *
  * @access   public
  * @return   View
  * @throws   Exception\Code404
  * @throws   Exception\Fatal
  * @since    1.0.1-dev, 2015-04-11
  * @version  1.2.0-dev
  */
 public function actionPage()
 {
     $query = DB::query('SELECT p FROM \\Model\\Page p WHERE p.rewrite = :rewrite');
     $query->param('rewrite', Router::getParam('rewrite'));
     $page = $query->single();
     if (!$page instanceof Model\Page) {
         throw new Exception\Code404('Page does not exist.');
     }
     $this->addBreadCrumb($page->getTitle());
     $this->setTitle($page->getTitle());
     $this->setDescription($page->getDescription());
     $this->setKeywords($page->getKeywords());
     $entityConfig = ViewEntity\Configurator::factory($page);
     $entityConfig->setFields(['content']);
     $viewEntity = ViewEntity::factory($entityConfig);
     return $viewEntity->getView();
 }
예제 #2
0
 /**
  * Constructor.
  *
  * @access   public
  * @param    ViewEntity $oEntity
  * @param    string     $sFieldName
  * @param    ModelCore  $oModel
  * @throws   ORM\Mapping\MappingException
  * @throws   Exception\Fatal
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 public function __construct(ViewEntity $oEntity, $sFieldName, ModelCore &$oModel)
 {
     $this->oEntity = $oEntity;
     $this->sName = $sFieldName;
     $this->oModel = $oModel;
     // check if entity has locales
     $sTypeFromModel = NULL;
     $oLocales = $this->oModel->hasLocales() ? $this->oModel->getLocales() : FALSE;
     /* @var $oLocales \Plethora\ModelCore\Locales */
     // get data form field view
     if ($this->oModel->hasField($sFieldName)) {
         $this->mValue = $this->oModel->{$sFieldName};
         if (in_array($sFieldName, $this->oModel->getMetadata()->getFieldNames())) {
             $aMapping = $this->oModel->getMetadata()->getFieldMapping($sFieldName);
             $sTypeFromModel = $aMapping['type'];
         } else {
             $sTypeFromModel = 'associacion';
         }
     } elseif ($oLocales !== FALSE && $oLocales->hasField($sFieldName)) {
         $this->mValue = $oLocales->{$sFieldName};
         if (in_array($sFieldName, $oLocales->getMetadata()->getFieldNames())) {
             $aMapping = $oLocales->getMetadata()->getFieldMapping($sFieldName);
             $sTypeFromModel = $aMapping['type'];
         } else {
             $sTypeFromModel = 'associacion';
         }
     }
     $this->sTypeFromModel = $sTypeFromModel;
     // change value of field if it's associacion
     if ($this->sTypeFromModel === 'associacion') {
         if ($this->oEntity->getConfigurator()->getCurrentLevel() < $this->oEntity->getConfigurator()->getMaxLevel()) {
             $oAssociacion = $this->mValue;
             /* @var $oAssociacion ModelCore */
             $aEntityFields = $this->getEntity()->getConfigurator()->getFields();
             if (!isset($aEntityFields[$this->getName()])) {
                 $this->mValue = $oAssociacion;
             } elseif ($oAssociacion instanceof ORM\PersistentCollection) {
                 /* @var $oCollection ORM\PersistentCollection */
                 $oCollection = $oAssociacion;
                 if ($oCollection->count() > 0) {
                     $aList = $oCollection->toArray();
                     $oTmpModelRelation = array_shift($aList);
                     /* @var $oTmpModelRelation ModelCore */
                     array_unshift($aList, $oTmpModelRelation);
                     unset($oTmpModelRelation);
                     $oConfigurator = ViewList\Configurator::factory()->setList($aList)->setFields($aEntityFields[$this->getName()])->setCurrentLevel($this->oEntity->getConfigurator()->getCurrentLevel() + 1)->setMaxLevel($this->oEntity->getConfigurator()->getMaxLevel())->setProfile($this->oEntity->getConfigurator()->getProfile());
                     $this->mValue = ViewList::factory($oConfigurator)->getView()->render();
                 }
             } elseif ($oAssociacion instanceof ModelCore) {
                 /* @var $oAssociacion ModelCore */
                 $oConfigurator = ViewEntity\Configurator::factory($oAssociacion)->setFields($aEntityFields[$this->getName()])->setCurrentLevel($this->oEntity->getConfigurator()->getCurrentLevel() + 1)->setMaxLevel($this->oEntity->getConfigurator()->getMaxLevel())->setProfile($this->oEntity->getConfigurator()->getProfile());
                 $this->mValue = ViewEntity::factory($oConfigurator)->getView()->render();
             }
         } else {
             $this->mValue = '!ENTITY TREE LEVEL REACHED!';
         }
     }
     // if it's not an associacion, format value of particular field
     if ($this->mValue !== NULL) {
         $aFormatters = $this->oModel->getConfig()->getFieldFormatters($this->sName);
         $sProfile = $this->getEntity()->getConfigurator()->getProfile();
         $this->mOriginalValue = $this->mValue;
         foreach ($aFormatters as $oFormatter) {
             /* @var $oFormatter \Plethora\View\FieldFormatter */
             if ($oFormatter->isAvailableFor($sProfile)) {
                 $oFormatter->setField($this);
                 if (is_array($this->mValue)) {
                     $this->mValue = $oFormatter->formatArray($this->mValue);
                 } elseif ($this->mValue instanceof ORM\PersistentCollection) {
                     $mValueToRefactor = $this->mValue;
                     /* @var $mValueToRefactor ORM\PersistentCollection */
                     $this->mValue = $oFormatter->formatArray($mValueToRefactor->toArray());
                 } else {
                     $this->mValue = $oFormatter->format($this->mValue);
                 }
             }
         }
         if (is_array($this->mValue) || is_object($this->mValue) && !method_exists($this->mValue, '__toString')) {
             throw new Exception\Fatal(__('Field value ":file" need to be formatted to string format (:type at the moment).', ['file' => $this->sName, 'type' => gettype($this->mValue)]));
         }
     }
 }
예제 #3
0
 /**
  * Prepare list of entities for \Plethora\View.
  *
  * @access     private
  * @since      1.0.0-alpha
  * @version    1.0.0-alpha
  */
 private function prepare()
 {
     // get html class
     $sChangedClass = str_replace(['\\', 'Model_'], ['_', ''], $this->getModelClassName());
     $this->sHtmlClass = strtolower($sChangedClass);
     // set path to View to single row for particular Model
     $sViewSingleRowByClass = $this->sViewPathSingleRowDefault . '__' . $this->sHtmlClass;
     if (View::viewExists($sViewSingleRowByClass)) {
         $this->sViewPathSingleRow = $sViewSingleRowByClass;
     }
     // set path to View for the whole list
     $sViewListByClass = $this->sViewPathListDefault . '__' . $this->sHtmlClass;
     if (View::viewExists($sViewListByClass)) {
         $this->sViewPathList = $sViewListByClass;
     }
     // prepare entities
     foreach ($this->getConfigurator()->getList() as $oEntityFromModel) {
         /* @var $oEntityFromModel \Plethora\ModelCore */
         $oConfigurator = ViewEntity\Configurator::factory($oEntityFromModel)->setFields($this->getConfigurator()->getFields())->setMaxLevel($this->getConfigurator()->getMaxLevel())->setCurrentLevel($this->getConfigurator()->getCurrentLevel())->setProfile($this->getConfigurator()->getProfile())->setViewListReference($this);
         $oViewEntity = ViewEntity::factory($oConfigurator);
         $oViewEntity->setViewFieldPath($this->getViewPathField());
         $this->aListPrepared[] = $oViewEntity;
     }
 }