protected function beforeSave() { if ($bResult = parent::beforeSave()) { $this->setDateUpdate(date("Y-m-d H:i:s")); } return $bResult; }
protected function beforeSave() { if ($bResult = parent::beforeSave()) { $oValueType = $this->getValueTypeObject(); $oValueType->beforeSaveValue(); } return $bResult; }
/** * Определяем правила валидации */ public function Init() { parent::Init(); $this->aValidateRules[] = array('forum_title', 'string', 'min' => 2, 'max' => 100, 'allowEmpty' => false, 'label' => $this->Lang_Get('plugin.forum.create_title')); $this->aValidateRules[] = array('forum_url', 'url', 'label' => $this->Lang_Get('plugin.forum.create_url')); $this->aValidateRules[] = array('forum_url', 'url_unique', 'label' => $this->Lang_Get('plugin.forum.create_url')); $this->aValidateRules[] = array('forum_url', 'url_bad', 'label' => $this->Lang_Get('plugin.forum.create_url')); $this->aValidateRules[] = array('forum_limit_rating_topic', 'number', 'label' => $this->Lang_Get('plugin.forum.create_rating')); $this->aValidateRules[] = array('forum_sort', 'sort_check', 'label' => $this->Lang_Get('plugin.forum.create_sort')); }
/** * Определяем правила валидации */ public function Init() { parent::Init(); $this->aValidateRules[] = array('post_title', 'string', 'min' => Config::Get('plugin.forum.post.title_min_length'), 'max' => Config::Get('plugin.forum.post.title_max_length'), 'allowEmpty' => true, 'label' => $this->Lang_Get('plugin.forum.post_create_title'), 'on' => array('post')); $this->aValidateRules[] = array('post_text_source', 'string', 'min' => 5, 'max' => Config::Get('plugin.forum.post.text_max_length'), 'allowEmpty' => false, 'label' => $this->Lang_Get('plugin.forum.post_create_text'), 'on' => array('topic', 'post')); $this->aValidateRules[] = array('post_text_source', 'post_unique', 'on' => array('topic', 'post')); if (!$this->User_IsAuthorization()) { $this->aValidateRules[] = array('guest_name', 'string', 'min' => 2, 'max' => 50, 'allowEmpty' => false, 'label' => $this->Lang_Get('plugin.forum.guest_name'), 'on' => array('topic', 'post')); } }
protected function beforeDelete() { if ($bResult = parent::beforeDelete()) { /** * Удаляем превью */ if ($this->getIsPreview() and $oMedia = $this->getMedia()) { $this->Media_RemoveFilePreview($oMedia, $this); } } return $bResult; }
/** * Выполняется перед удалением * * @return bool */ protected function beforeDelete() { if ($bResult = parent::beforeDelete()) { /** * Запускаем удаление дочерних ролей */ if ($aCildren = $this->getChildren()) { foreach ($aCildren as $oChildren) { $oChildren->Delete(); } } } return $bResult; }
/** * Выполняется перед удалением сущности * * @return bool */ protected function beforeDelete() { if ($bResult = parent::beforeDelete()) { /** * Нужно сбросить группу у разрешений */ $aPermissionItems = $this->Rbac_GetPermissionItemsByGroupId($this->getId()); foreach ($aPermissionItems as $oPermission) { $oPermission->setGroupId(null); $oPermission->Update(); } } return $bResult; }
protected function beforeDelete() { if ($bResult = parent::beforeDelete()) { /** * Удаляем все связи */ $aTargets = $this->getTargets(); foreach ($aTargets as $oTarget) { $oTarget->Delete(); } /** * Удаляем все файлы медиа */ $this->Media_DeleteFiles($this); } return $bResult; }
protected function afterDelete() { parent::afterDelete(); /** * Удаляем варианты ответов */ $aAnswerItems = $this->Poll_GetAnswerItemsByPollId($this->getId()); foreach ($aAnswerItems as $oAnswer) { $oAnswer->Delete(); } /** * Удаляем голосования */ $aVoteItems = $this->Poll_GetVoteItemsByPollId($this->getId()); foreach ($aVoteItems as $oVote) { $oVote->Delete(); } }
protected function afterSave() { parent::afterSave(); if ($this->_isNew()) { /** * Отмечаем факт голосования в опросе и вариантах */ $oPoll = $this->getPoll(); $aAnswerItems = $this->getAnswersObject(); if ($aAnswerItems) { foreach ($aAnswerItems as $oAnswer) { $oAnswer->setCountVote($oAnswer->getCountVote() + 1); $oAnswer->Update(); } $oPoll->setCountVote($oPoll->getCountVote() + 1); } else { $oPoll->setCountAbstain($oPoll->getCountAbstain() + 1); } $oPoll->Update(0); } }
/** * Для сущности со связью RELATION_TYPE_TREE возвращает список всех потомков * * @param EntityORM $oEntity Объект сущности * @return array */ protected function _GetDescendantsOfEntity($oEntity) { if ($oEntity->_isUsedRelationType(EntityORM::RELATION_TYPE_TREE)) { $aRelationsData = $oEntity->_getRelationsData(); if (array_key_exists('descendants', $aRelationsData)) { $aDescendants = $aRelationsData['descendants']; } else { $aDescendants = array(); if ($aChildren = $oEntity->getChildren()) { $aTree = self::buildTree($aChildren); foreach ($aTree as $aItem) { $aDescendants[] = $aItem['entity']; } } } if (is_array($aDescendants)) { $oEntity->setDescendants($aDescendants); return $aDescendants; } } return false; }
/** * Определяем правила валидации */ public function Init() { parent::Init(); $this->aValidateRules[] = array('topic_title', 'string', 'min' => 2, 'max' => 100, 'allowEmpty' => false, 'label' => $this->Lang_Get('plugin.forum.new_topic_title')); $this->aValidateRules[] = array('topic_description', 'string', 'max' => 100, 'allowEmpty' => true, 'label' => $this->Lang_Get('plugin.forum.new_topic_description')); }
/** * Построение дополнительного фильтра * Здесь учитываются ключи фильтра вида #* * * @param array $aFilter Фильтр * @param EntityORM $oEntitySample Объект сущности * @return array */ public function BuildFilterMore($aFilter, $oEntitySample) { // Сортировка $sOrder = ''; if (isset($aFilter['#order'])) { if (!is_array($aFilter['#order'])) { $aFilter['#order'] = array($aFilter['#order']); } foreach ($aFilter['#order'] as $key => $value) { if (is_numeric($key)) { $key = $value; $value = 'asc'; } elseif (!in_array($value, array('asc', 'desc'))) { $value = 'asc'; } if (substr($key, 0, 1) == '#') { /** * Используем "как есть" */ $key = ltrim($key, '#'); } else { /** * Проверяем на простые выражения: field1 + field2 * field3 */ $aKeyPath = preg_split("#\\s?([\\-\\+\\*\\\\])\\s?#", $key, -1, PREG_SPLIT_DELIM_CAPTURE); if (count($aKeyPath) > 2) { $key = ''; foreach ($aKeyPath as $i => $sKey) { if ($i % 2 == 0) { $key .= 't.' . $this->oDb->escape($oEntitySample->_getField(trim($sKey)), true); } else { $key .= " {$sKey} "; } } } else { /** * Проверяем на FIELD:id -> FIELD(id,?a) */ $aKeys = explode(':', $key); if (count($aKeys) == 2) { if (strtolower($aKeys[0]) == 'field' and is_array($aFilter['#order'][$key]) and count($aFilter['#order'][$key])) { $key = 'FIELD(t.' . $this->oDb->escape($oEntitySample->_getField(trim($aKeys[1])), true) . ',' . join(',', $aFilter['#order'][$key]) . ')'; $value = ''; } else { /** * Неизвестное выражение */ continue; } } else { /** * Пропускаем экранирование функций */ if (!in_array($key, array('rand()'))) { /** * Проверяем наличие префикса таблицы */ if (!strpos($oEntitySample->_getField($key), '.')) { $key = 't.' . $this->oDb->escape($oEntitySample->_getField($key), true); } else { $key = $oEntitySample->_getField($key); } } } } } $sOrder .= " {$key} {$value},"; } $sOrder = trim($sOrder, ','); if ($sOrder != '') { $sOrder = "ORDER BY {$sOrder}"; } } // Постраничность if (isset($aFilter['#page']) and is_array($aFilter['#page']) and count($aFilter['#page']) == 2) { // array(2,15) - 2 - page, 15 - count $aFilter['#limit'] = array(($aFilter['#page'][0] - 1) * $aFilter['#page'][1], $aFilter['#page'][1]); } // Лимит $sLimit = ''; if (isset($aFilter['#limit'])) { // допустимы варианты: limit=10 , limit=array(10) , limit=array(10,15) $aLimit = $aFilter['#limit']; if (is_numeric($aLimit)) { $iBegin = 0; $iEnd = $aLimit; } elseif (is_array($aLimit)) { if (count($aLimit) > 1) { $iBegin = $aLimit[0]; $iEnd = $aLimit[1]; } else { $iBegin = 0; $iEnd = $aLimit[0]; } } $sLimit = "LIMIT {$iBegin}, {$iEnd}"; } // Группировка $sGroup = ''; if (isset($aFilter['#group'])) { if (!is_array($aFilter['#group'])) { $aFilter['#group'] = array($aFilter['#group']); } foreach ($aFilter['#group'] as $sField) { if (substr($sField, 0, 1) == '#') { $sGroup .= ltrim($sField, '#') . ','; } else { $sField = $this->oDb->escape($oEntitySample->_getField($sField), true); $sGroup .= " t.{$sField},"; } } $sGroup = trim($sGroup, ','); if ($sGroup != '') { $sGroup = "GROUP BY {$sGroup}"; } } // Определение полей в select $sSelect = ''; if (isset($aFilter['#select'])) { // todo: добавить экранирование полей с учетом префикса таблицы if (!is_array($aFilter['#select'])) { $aFilter['#select'] = array($aFilter['#select']); } $sSelect = join(', ', $aFilter['#select']); } return array($sOrder, $sLimit, $sGroup, $sSelect); }
/** * Построение дополнительного фильтра * Здесь учитываются ключи фильтра вида #* * * @param array $aFilter Фильтр * @param EntityORM $oEntitySample Объект сущности * @return array */ public function BuildFilterMore($aFilter, $oEntitySample) { // Сортировка $sOrder = ''; if (isset($aFilter['#order'])) { if (!is_array($aFilter['#order'])) { $aFilter['#order'] = array($aFilter['#order']); } foreach ($aFilter['#order'] as $key => $value) { if (is_numeric($key)) { $key = $value; $value = 'asc'; } elseif (!in_array($value, array('asc', 'desc'))) { $value = 'asc'; } $key = $this->oDb->escape($oEntitySample->_getField($key), true); $sOrder .= " {$key} {$value},"; } $sOrder = trim($sOrder, ','); if ($sOrder != '') { $sOrder = "ORDER BY {$sOrder}"; } } // Постраничность if (isset($aFilter['#page']) and is_array($aFilter['#page']) and count($aFilter['#page']) == 2) { // array(2,15) - 2 - page, 15 - count $aFilter['#limit'] = array(($aFilter['#page'][0] - 1) * $aFilter['#page'][1], $aFilter['#page'][1]); } // Лимит $sLimit = ''; if (isset($aFilter['#limit'])) { // допустимы варианты: limit=10 , limit=array(10) , limit=array(10,15) $aLimit = $aFilter['#limit']; if (is_numeric($aLimit)) { $iBegin = 0; $iEnd = $aLimit; } elseif (is_array($aLimit)) { if (count($aLimit) > 1) { $iBegin = $aLimit[0]; $iEnd = $aLimit[1]; } else { $iBegin = 0; $iEnd = $aLimit[0]; } } $sLimit = "LIMIT {$iBegin}, {$iEnd}"; } // Группировка $sGroup = ''; if (isset($aFilter['#group'])) { if (!is_array($aFilter['#group'])) { $aFilter['#group'] = array($aFilter['#group']); } foreach ($aFilter['#group'] as $sField) { $sField = $this->oDb->escape($oEntitySample->_getField($sField), true); $sGroup .= " {$sField},"; } $sGroup = trim($sGroup, ','); if ($sGroup != '') { $sGroup = "GROUP BY {$sGroup}"; } } return array($sOrder, $sLimit, $sGroup); }
/** * Выполняется перед удалением сущности * * @return bool */ protected function beforeDelete() { if ($bResult = parent::beforeDelete()) { /** * Сначала удаляем стандартные значения */ $this->Property_RemoveValueByPropertyId($this->getId()); /** * Удаляем значения тегов */ $this->Property_RemoveValueTagByPropertyId($this->getId()); /** * Удаляем значения селектов */ $this->Property_RemoveValueSelectByPropertyId($this->getId()); /** * Удаляем сами варианты селектов */ $this->Property_RemoveSelectByPropertyId($this->getId()); } return $bResult; }
/** * Определяем правила валидации */ public function Init() { parent::Init(); $this->aValidateRules[] = array('topic_title', 'string', 'min' => Config::Get('plugin.forum.topic.title_min_length'), 'max' => Config::Get('plugin.forum.topic.title_max_length'), 'allowEmpty' => false, 'label' => $this->Lang_Get('plugin.forum.new_topic_title')); $this->aValidateRules[] = array('topic_description', 'string', 'max' => Config::Get('plugin.forum.topic.descr_max_length'), 'allowEmpty' => true, 'label' => $this->Lang_Get('plugin.forum.new_topic_description')); }