コード例 #1
0
ファイル: CheckboxRelation.php プロジェクト: ktrzos/plethora
 /**
  * Reset form values.
  *
  * @access   protected
  * @return   Form\Field
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 protected function resetValue()
 {
     $this->aFormMethodValues = $this->getFormObject()->getMethodValue();
     if ($this->getFormObject()->isFieldsNameWithPrefix()) {
         $mSentData = Helper\Arrays::path($this->aFormMethodValues, $this->getFormObject()->getName() . '.' . $this->getName(), FALSE);
     } else {
         $mSentData = Helper\Arrays::get($this->aFormMethodValues, $this->getName(), FALSE);
     }
     if ($mSentData !== FALSE) {
         foreach ($mSentData as $sLang => $aAllDefaultValuesForLang) {
             foreach ($aAllDefaultValuesForLang as $i => $mSingleValue) {
                 foreach ($mSingleValue as $i => &$mValue) {
                     $mValue = DB::find($this->getRelatedModelName(), $mValue);
                 }
                 $this->setValue($mSingleValue, $i, $sLang);
             }
         }
     } else {
         $aDefaultValue = $this->getFormObject()->getDefaultVal($this->getName());
         foreach ($aDefaultValue as $sLang => $aValues) {
             $aDefaultValue[$sLang] = [$aValues];
         }
         $this->setValue($aDefaultValue);
     }
     return $this;
 }
コード例 #2
0
ファイル: SelectRelation.php プロジェクト: ktrzos/plethora
 /**
  * Make some actions / operations for particular field just before form
  * validation has
  *
  * @access   public
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 public function beforeValidation()
 {
     if ($this->getRelatedModelName() === NULL) {
         throw new Exception\Fatal('To continue, there must be a related model name added by setRelatedModelName() method.');
     }
     if ($this->getFormObject()->isSubmitted()) {
         $aValue = $this->getValue();
         foreach ($aValue as $sLang => $aAllDefaultValuesForLang) {
             foreach ($aAllDefaultValuesForLang as $i => $mSingleValue) {
                 $oModel = \Plethora\DB::find($this->getRelatedModelName(), $mSingleValue);
                 $this->setValue($oModel, $i, $sLang);
             }
         }
     }
 }
コード例 #3
0
ファイル: File.php プロジェクト: ktrzos/plethora
 /**
  * Remove file by ID.
  *
  * @static
  * @access   public
  * @param    integer $iFileID
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 public static function deleteFile($iFileID)
 {
     // get file object and its path
     $oFile = DB::find('\\Model\\File', $iFileID);
     /* @var $oFile \Model\File */
     $sPath = $oFile->getPath() . DS . $oFile->getNameWithExt();
     // if it's an image, remove all its styles
     if (in_array($oFile->getExt(), ['jpg', 'jpeg', 'gif', 'png', 'tiff'])) {
         ImageStyles::removeStyledImgCache($sPath);
     }
     // remove file
     \FileManager::delete($sPath);
     // remove from database
     $oFile->remove();
     //		\Plethora\DB::flush();
 }
コード例 #4
0
ファイル: User.php プロジェクト: ktrzos/plethora
 /**
  * Get currently logged user.
  *
  * @static
  * @access   public
  * @return   User
  * @since    2.0.2, 2013-12-25
  * @version  2.1.2-dev
  */
 public static function getLoggedUser()
 {
     if (static::$loggedUser === NULL && Session::get('uid') !== NULL) {
         static::$loggedUser = DB::find('\\Model\\User', Session::get('uid'));
     }
     return static::$loggedUser;
 }
コード例 #5
0
ファイル: Item.php プロジェクト: ktrzos/plethora
 /**
  * Constructor
  *
  * @access     public
  * @since      1.1.2-dev
  * @version    1.1.3-dev
  */
 public function __construct()
 {
     parent::__construct();
     $this->locales = new \Doctrine\Common\Collections\ArrayCollection();
     // get menu ID
     if (Router::getCurrentRouteName() === 'backend' && in_array(Router::getParam('action'), ['add', 'edit'])) {
         $menuID = (int) Router::getParam('id');
         $this->menu = DB::find('\\Model\\Menu', $menuID);
     }
 }
コード例 #6
0
ファイル: FileModel.php プロジェクト: ktrzos/plethora
 /**
  * Method is called by Form object when this particular form is used (sent).
  *
  * @access   protected
  * @throws   Exception\Fatal
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 protected function whenFormSubmitted()
 {
     // get sent data
     $sentFileData = $this->getSentFileArray();
     // loop trough all sent data
     foreach ($sentFileData as $sLang => $allDefaultValuesForLang) {
         foreach ($allDefaultValuesForLang as $i => $dataBatch) {
             // create file broker (if not exists)
             $broker = Arrays::path($this->aFileBrokers, $sLang . '.' . $i, FALSE);
             if ($broker === FALSE) {
                 $parent = $this->isMultilanguage() ? $this->getFormObject()->getModel()->getLocales() : $this->getFormObject()->getModel();
                 $broker = new $this->sBrokerModel();
                 /* @var $broker ModelCore\FileBroker */
                 if (!$broker instanceof ModelCore\FileBroker) {
                     throw new Exception\Fatal('Given bad class name (`' . get_class($broker) . '`). ' . 'Not a `ModelCore\\FileBroker` class.');
                 }
                 $broker->setParent($parent);
             }
             // if file was uploaded earlier and is in "temporary file" field
             $formValues = $this->getFormObject()->getMethodValue();
             $tempValue = Arrays::get($formValues, 'temp_file_' . $this->getName() . '_' . $sLang . '_' . $i);
             if (!empty($tempValue)) {
                 $oFile = DB::find('\\Model\\File', $tempValue);
                 /* @var $oFile \Model\File */
                 Arrays::createMultiKeys($this->aFileTemp, $sLang . '.' . $i, $oFile);
             }
             // if file has been sent by $_FILE method
             if (isset($dataBatch['tmp_name']) && $dataBatch['tmp_name'] !== '' && $dataBatch['size'] >= 0) {
                 $broker->setTempData($dataBatch);
             }
             // set file to filebroker
             $oFileForBroker = Arrays::path($this->aFileTemp, $sLang . '.' . $i, FALSE);
             if ($oFileForBroker !== FALSE) {
                 $broker->setFile($oFileForBroker);
             }
             // set broker as fields value
             Arrays::createMultiKeys($this->aFileBrokers, $sLang . '.' . $i, $broker);
             $this->setValue($broker, $i, $sLang);
         }
     }
 }
コード例 #7
0
ファイル: Backend.php プロジェクト: ktrzos/plethora
 /**
  * Load Model for controller actions usage.
  *
  * @access   protected
  * @throws   Exception
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 protected function loadModelForActions()
 {
     $iId = (int) Router::getParam('id');
     $sModel = $this->getModel()->getClass();
     $oModel = DB::find($sModel, $iId);
     if ($oModel === NULL) {
         throw new Exception\Code404(__('Content with particular id does not exist.'));
     }
     $this->setModel($oModel);
 }
コード例 #8
0
ファイル: local_actions.php プロジェクト: ktrzos/plethora
<?php

\Plethora\Router\LocalActions::addLocalAction(__('Edit page'), 'page', 'backend')->setParameters(array('controller' => 'pages', 'action' => 'edit'))->setBuilder(function (\Plethora\Router\LocalActions\Action $oAction) {
    $sPageRewrite = (int) \Plethora\Router::getParam('rewrite');
    $aPage = \Plethora\DB::query('SELECT p.id FROM \\Model\\Page p WHERE p.rewrite = :rewrite')->param('rewrite', $sPageRewrite)->single();
    $oAction->setParameter('id', $aPage['id']);
});
\Plethora\Router\LocalActions::addLocalAction(__('Preview'), 'backend', 'page')->setConditions(array('controller' => 'pages', 'action' => 'edit'))->setBuilder(function (\Plethora\Router\LocalActions\Action $oAction) {
    $iNewsID = (int) \Plethora\Router::getParam('id');
    $oPage = \Plethora\DB::find('Model\\Page', $iNewsID);
    /* @var $oPage \Model\Page */
    $oAction->setParameter('rewrite', $oPage->getRewrite());
});
コード例 #9
0
ファイル: Items.php プロジェクト: ktrzos/plethora
 /**
  * Change main (start or parent) breadcrumbs and/or title for this backend
  * constructor.
  *
  * @access     protected
  * @since      1.1.3-dev, 2015-08-20
  * @version    1.2.0-dev
  */
 protected function alterBreadcrumbsTitleMain()
 {
     parent::alterBreadcrumbsTitleMain();
     $this->setTitle(__('Management panel') . ' - ');
     $iMenuID = Router::getParam('id');
     $sAction = Router::getParam('action');
     if ($iMenuID === FALSE || $sAction === FALSE) {
         throw new Exception\Code404();
     }
     if ($sAction === 'edit') {
         $oItem = DB::find('\\Model\\Menu\\Item', $iMenuID);
         /* @var $oItem \Model\Menu\Item */
         $iMenuID = $oItem->getMenu()->getId();
     }
     $this->removeBreadcrumb();
     $this->addBreadCrumb(__('Menu list'), Route::backendUrl('menu', 'list'));
     $this->addBreadCrumb(__('Menu items list'), Route::backendUrl(Router::getControllerName(), 'list', $iMenuID));
 }