コード例 #1
0
ファイル: PostService.php プロジェクト: cmsgears/module-cms
 /**
  * @param Binder $binder
  * @return boolean
  */
 public static function bindCategories($binder)
 {
     $postId = $binder->binderId;
     $categories = $binder->bindedData;
     // Clear all existing mappings
     ModelCategory::deleteByParentIdType($postId, CmsGlobal::TYPE_POST);
     if (isset($categories) && count($categories) > 0) {
         foreach ($categories as $key => $value) {
             if (isset($value) && $value > 0) {
                 $toSave = new ModelCategory();
                 $toSave->parentId = $postId;
                 $toSave->parentType = CmsGlobal::TYPE_POST;
                 $toSave->categoryId = $value;
                 $toSave->save();
             }
         }
     }
     return true;
 }
コード例 #2
0
 /**
  * @return array - ModelCategory associated with parent
  */
 public function getModelCategories()
 {
     $parentType = $this->categoryType;
     return $this->hasMany(ModelCategory::className(), ['parentId' => 'id'])->where("parentType='{$parentType}'");
 }