コード例 #1
0
ファイル: Categories.php プロジェクト: suyuanen/trotri
 /**
  * 通过主键,删除一条记录
  * @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;
 }
コード例 #2
0
ファイル: PlgProfile.php プロジェクト: suyuanen/trotri
 /**
  * 新增或编辑后执行
  * @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);
 }
コード例 #3
0
ファイル: Comments.php プロジェクト: suyuanen/trotri
 /**
  * 通过主键,删除多条记录
  * @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;
 }
コード例 #4
0
ファイル: FpPosts.php プロジェクト: suyuanen/trotri
 /**
  * 获取“所属模型”验证规则
  * @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'));
 }
コード例 #5
0
ファイル: FpCategories.php プロジェクト: suyuanen/trotri
 /**
  * 获取“类别名”验证规则
  * @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));
 }