Ejemplo n.º 1
0
 /**
  * 通过主键,删除一条记录
  * @param integer $categoryId
  * @return integer
  */
 public function removeByPk($categoryId)
 {
     if (($categoryId = (int) $categoryId) <= 0) {
         return false;
     }
     $tableName = $this->getTblprefix() . TableNames::getCategories();
     $sql = $this->getCommandBuilder()->createDelete($tableName, '`category_id` = ?');
     $rowCount = $this->delete($sql, $categoryId);
     return $rowCount;
 }
Ejemplo n.º 2
0
 /**
  * 新增或编辑后执行
  * @param string $context
  * @param array $row
  * @param mixed $params
  * @return void
  */
 public function onAfterSave($context, array &$row, $params = null)
 {
     $isCreate = $context === 'posts\\services\\Posts::create' ? true : false;
     $isModify = $context === 'posts\\services\\Posts::modifyByPk' ? true : false;
     if (!$isCreate && !$isModify) {
         return;
     }
     if (($postId = (int) $params) <= 0) {
         return;
     }
     $service = Service::getInstance('Posts', 'posts');
     $fields = $service->getModuleFieldsByPostId($postId);
     if ($fields === array()) {
         return;
     }
     $attributes = array();
     foreach ($fields as $name => $field) {
         if (isset($row[$name])) {
             $attributes[$name] = $row[$name];
         } else {
             if ($isCreate) {
                 $attributes[$name] = '';
             }
         }
     }
     if ($attributes === array()) {
         return;
     }
     $db = $service->getDb();
     $dbProxy = $db->getDbProxy();
     $tableName = $db->getTblprefix() . TableNames::getPostProfile();
     $profile = Profile::getInstance($tableName, $postId, $dbProxy);
     $profile->save($attributes);
 }
Ejemplo n.º 3
0
 /**
  * 通过主键,删除多条记录
  * @param array|integer $commentIds
  * @return integer
  */
 public function batchRemoveByPk($commentIds, array $params = array())
 {
     $commentIds = Clean::positiveInteger($commentIds);
     if ($commentIds === false) {
         return false;
     }
     if (is_array($commentIds)) {
         $commentIds = implode(', ', $commentIds);
     }
     $tableName = $this->getTblprefix() . TableNames::getComments();
     $condition = '`comment_id` IN (' . $commentIds . ')';
     $sql = $this->getCommandBuilder()->createDelete($tableName, $condition);
     $rowCount = $this->delete($sql);
     return $rowCount;
 }
Ejemplo n.º 4
0
 /**
  * 获取“所属模型”验证规则
  * @param mixed $value
  * @return array
  */
 public function getModuleIdRule($value)
 {
     return array('DbExists' => new validator\DbExistsValidator($value, true, Lang::_('SRV_FILTER_POSTS_MODULE_ID_EXISTS'), $this->getDbProxy(), TableNames::getModules(), 'module_id'));
 }
Ejemplo n.º 5
0
 /**
  * 获取“类别名”验证规则
  * @param mixed $value
  * @return array
  */
 public function getCategoryNameRule($value)
 {
     return array('MinLength' => new validator\MinLengthValidator($value, 2, Lang::_('SRV_FILTER_POST_CATEGORIES_CATEGORY_NAME_MINLENGTH')), 'MaxLength' => new validator\MaxLengthValidator($value, 20, Lang::_('SRV_FILTER_POST_CATEGORIES_CATEGORY_NAME_MAXLENGTH')), 'DbExists2' => new validator\DbExists2Validator($value, false, Lang::_('SRV_FILTER_POST_CATEGORIES_CATEGORY_NAME_UNIQUE'), $this->getDbProxy(), TableNames::getCategories(), 'category_name', 'category_pid', $this->category_pid));
 }