Пример #1
0
 /**
  * Contructor. The search engine form is generated in here.
  *
  * @access    public
  * @param     ModelCore $oModel
  * @since     1.0.0-alpha
  * @version   1.0.0-alpha
  */
 public function __construct(ModelCore $oModel)
 {
     $this->oModel = $oModel;
     $sModelClass = $oModel->getClass();
     $aQueryParams = Router::getQueryStringParams();
     $aDefaults = [];
     $sFormName = 'search_engine_for_' . str_replace('\\', '_', strtolower($sModelClass));
     if (count($aQueryParams) > 0) {
         foreach ($aQueryParams as $sKey => $sValue) {
             $aDefaults[$sKey] = ['und' => [0 => $sValue]];
         }
     }
     $oForm = Form::factory($sFormName, $aDefaults)->setView($this->getFormView())->setFieldsNameWithPrefix(FALSE)->removeCsrfToken();
     $this->setForm($oForm);
 }
Пример #2
0
 /**
  * Generate config object of particular Model.
  *
  * @static
  * @author   Krzysztof Trzos
  * @access   protected
  * @return   ModelCore\MConfig
  * @since    2015-01-10
  * @version  1.1.1-dev, 2015-08-10
  */
 public static function generateConfig()
 {
     // get config
     $config = parent::generateConfig();
     // add fields
     $config->addField(Form\Field\Hidden::singleton('id'));
     $config->addField(Form\Field\Text::singleton('name')->setLabel(__('Name'))->setRequired());
     // return config
     return $config;
 }
Пример #3
0
 /**
  * Remove entity. If entity has been removed, delete related file.
  *
  * @access     public
  * @return    boolean
  * @since      1.0.0-alpha
  * @version    1.0.0-alpha
  */
 public function remove()
 {
     $bRemoved = parent::remove();
     if ($bRemoved) {
         // set path to file
         $sPath = $this->getPath() . DS . $this->getNameWithExt();
         // if it's an image, remove all its styles
         if (in_array($this->getExt(), ['jpg', 'jpeg', 'gif', 'png', 'tiff'])) {
             ImageStyles::removeStyledImgCache($sPath);
         }
         // remove file
         \FileManager::delete($sPath);
     }
     return $bRemoved;
 }
Пример #4
0
 /**
  * Remove all data of this Model from database.
  *
  * @access   public
  * @return   boolean
  * @since    2.1.2-dev
  * @version  2.1.2-dev
  */
 public function remove()
 {
     if ((int) $this->id === 1) {
         Route::factory('home')->redirectTo();
     }
     parent::remove();
 }
Пример #5
0
 /**
  * Search engine configuration.
  *
  * @static
  * @access	 public
  * @return	 array
  * @since	 1.3.0-dev
  * @version	 1.3.0-dev
  */
 public static function getConfigSearchEngine()
 {
     $oConfig = parent::getConfigSearchEngine();
     $oConfig->addFromRel('locales', 'name');
     return $oConfig;
 }
Пример #6
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)]));
         }
     }
 }
Пример #7
0
 /**
  * Generate config object of particular Model.
  *
  * @overwritten
  * @static
  * @author     Krzysztof Trzos
  * @access     protected
  * @return    ModelCore\MConfig
  * @since      2015-01-10
  * @version    1.1.1-dev, 2015-08-10
  */
 public static function generateConfig()
 {
     // get all permissions list
     $aPermissions = [];
     $aResult = DB::queryList('\\Model\\User\\Permission')->execute();
     foreach ($aResult as $oPermission) {
         /* @var $oPermission Permission */
         $aPermissions[$oPermission->getId()] = ['value' => $oPermission->getId(), 'label' => $oPermission->getName()];
     }
     $config = parent::generateConfig();
     // return MConfig
     $config->addField(Form\Field\Hidden::singleton('id'));
     $config->addField(Form\Field\Text::singleton('name')->setRequired()->setLabel(__('Name')));
     $config->addField(Form\Field\CheckboxRelation::singleton('permissions')->setRelatedModelName('\\Model\\User\\Permission')->setColumnsAmount(3)->setOptions($aPermissions)->setLabel(__('Permissions')));
     return $config;
 }
Пример #8
0
 /**
  * Fields config for backend.
  *
  * @access   public
  * @return   ModelCore\MConfig
  * @since    1.0.0
  * @version  1.0.3-dev, 2015-04-29
  */
 protected static function generateConfig()
 {
     # create config
     $config = parent::generateConfig();
     # create fields
     $config->addField(Form\Field\Hidden::singleton('id')->setLabel('ID')->setDisabled());
     $config->addField(Form\Field\Select::singleton('published')->setOptions(['Nie', 'Tak'])->setLabel(__('Published'))->setRequired()->addRulesSet(Validator\RulesSetBuilder::factory()->addRule(['in_array', [':value', [1, 0]]])));
     $config->addField(Form\Field\Text::singleton('title')->setLabel(__('Title'))->setRequired());
     $config->addField(Form\Field\Text::singleton('rewrite')->setRequired()->setLabel(__('URL alias')));
     $config->addField(Form\Field\Text::singleton('keywords')->setLabel(__('Keywords')));
     $config->addField(Form\Field\ImageModel::singleton('image')->setBrokerModel('\\Model\\Page\\Image')->setUploadPath('uploads/page')->setRequired()->setLabel(__('Image'))->addRulesSet(Validator\RulesSetBuilder\ImageModel::factory()->allowedExt(':value', ['jpg', 'gif', 'png', 'jpeg'])));
     $config->addField(Form\Field\FileModel::singleton('files')->setBrokerModel('\\Model\\Page\\File')->setUploadPath('uploads/page_files')->setQuantity(0)->setLabel(__('Attachments'))->addRulesSet(Validator\RulesSetBuilder\ImageModel::factory()->allowedExt(':value', ['txt', 'pdf', 'docx', 'doc', 'rtf', 'zip'])));
     $config->addField(Form\Field\Textarea::singleton('description')->setLabel(__('Description')));
     $config->addField(Form\Field\Tinymce::singleton('content')->setRequired()->setLabel(__('Content')));
     # return config
     return $config;
 }
Пример #9
0
 /**
  * Remove all data of this Model from database.
  *
  * @access     public
  * @return    boolean
  * @since      1.0.0-alpha
  * @version    1.0.0-alpha
  */
 public function remove()
 {
     $oFile = $this->file;
     /* @var $oFile File */
     parent::remove();
     $oFile->decreaseUses();
 }