Esempio n. 1
0
 /**
  * generic is allowed rule
  *
  * @param ModelInterface $model
  * @param array $arrConfig supports
  * 		- ptable string 	optional if want to check isAllowed for another table than data from $arrRow
  * 		- property string  	optional column of current row for WHERE id=? statement, default pid
  * 		- value string		optional value if not want to check against a value of arrRow, default $arrRow[$pid]
  * 		- operation int 	operation integer for BackendUser::isAllowed
  *      - pid string        optional parent id column
  *
  * @return bool
  */
 public static function isAllowed(ModelInterface $model, array $arrConfig)
 {
     /** @var \BackendUser $objUser */
     $objUser = \BackendUser::getInstance();
     $arrRow = $model->getPropertiesAsArray();
     if (!isset($arrConfig['ptable'])) {
         return $objUser->isAllowed($arrConfig['operation'], $arrRow);
     }
     if (isset($arrConfig['ptable']) && $arrConfig['ptable'] !== true) {
         $strPTable = $arrConfig['ptable'];
     } else {
         $arrDefinition = Definition::getDataContainer($model->getProviderName());
         $strPTable = $arrDefinition['config']['ptable'];
     }
     $strPId = isset($arrConfig['pid']) ? $arrConfig['pid'] : 'pid';
     $strValue = isset($arrConfig['value']) ? $arrConfig['value'] : $arrRow[$strPId];
     $objParent = \Database::getInstance()->prepare("SELECT * FROM {$strPTable} WHERE id=?")->limit(1)->execute($strValue);
     return $objUser->isAllowed($arrConfig['operation'], $objParent->row());
 }
Esempio n. 2
0
 /**
  * Get activated
  *
  * @param Property $objProperty
  * @param ModelInterface $objModel
  *
  * @return Definition\SubPalette|null
  */
 public static function getActivePropertySubPalette(Property $objProperty, ModelInterface $objModel)
 {
     $objProperty->getDataContainer();
     $varValue = $objModel->getProperty($objProperty->getName());
     if ($objProperty->hasSubPalette($varValue)) {
         return $objProperty->getSubPalette($varValue);
     }
     return null;
 }
 /**
  * (PHP 5 &gt;= 5.1.0)<br/>
  * Returns an iterator for the current entry.
  * @link http://php.net/manual/en/recursiveiterator.getchildren.php
  * @return RecursiveIterator An iterator for the current entry.
  */
 public function getChildren()
 {
     $objProperty = $this->current();
     $varValue = $this->objModel->getProperty($objProperty->getName());
     return new ActivePropertyContainer($objProperty->getSubPalette($varValue), $this->objModel);
 }
Esempio n. 4
0
 /**
  * Create legacy model
  *
  * @param ModelInterface $model
  * @return \Model
  * @throws
  */
 public static function createLegacy(ModelInterface $model)
 {
     $class = \Model::getClassFromTable($model->getProviderName());
     if (!class_exists($class)) {
         throw new \RuntimeException(sprintf('No model class found for "%s"', $model->getProviderName()));
     }
     /** @var \Model $legacy */
     $legacy = new $class();
     $legacy->setRow($model->getPropertiesAsArray());
     return $legacy;
 }