/** * Add an expert to an expert to a group. Questions are linked to SocCodes and Groups are linked likewise * * @param \Experts $expert * @param \ExpertGroup $group * * @return \ExpertGroupMembers */ public function addExpertToGroup(\Experts $expert, \ExpertGroup $group) { $membership = new \ExpertGroupMembers(); $membership->setExpert($expert->getUsername()); $membership->setGroupName($group->getGroupName()); $membership->save(); return $membership; }
public function actionGetTreePages() { $result = array(); if (isset($_REQUEST['model']) && isset($_REQUEST['page'])) { $limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : 30; $model = $_REQUEST['model']; $id = $_REQUEST['id']; $bid = $_REQUEST['bid']; $p = isset($_REQUEST['page']) ? $_REQUEST['page'] - 1 : 0; $items = array(); $isParent = false; $count = 0; $criteria = new CDbCriteria(); switch ($model) { case 'news': $criteria->addCondition("is_active = 1"); $criteria->limit = $limit; $criteria->offset = $p * $limit; $items = News::model()->findAll($criteria); if (is_array($items) && count($items)) { foreach ($items as $item) { $checked = BannersPagesRelation::model()->findByAttributes(array("banner_id" => $bid, "object_id" => $item->id, "model" => $model)) ? true : false; $result[] = array('name' => $item->name, 'model' => $model, 'id' => $item->id, 'oid' => $item->id, 'isParent' => $isParent, "checked" => $checked); } } break; case 'articles_categories': $criteria->addCondition("is_active = 1"); $criteria->limit = $limit; $criteria->offset = $p * $limit; $items = ArticlesCategories::model()->findAll($criteria); if ($id == 0) { $isParent = true; $model = 'articles'; } if (is_array($items) && count($items)) { foreach ($items as $item) { $criteria = new CDbCriteria(); $criteria->addCondition("category_id = :cid AND is_active = 1"); $criteria->params = array(":cid" => $item->id); $count = Articles::model()->count($criteria); $checked = BannersPagesRelation::model()->findByAttributes(array("banner_id" => $bid, "object_id" => $item->id, "model" => $model)) ? true : false; $result[] = array('name' => $item->name, 'model' => $model, 'id' => $item->id, 'oid' => $item->id, 'count' => $count, 'page' => $p, 'pageSize' => 30, 'isParent' => $isParent, "checked" => $checked); } } break; case 'articles': $criteria->addCondition("category_id = :cid AND is_active = 1"); $criteria->limit = $limit; $criteria->offset = $p * $limit; $criteria->params = array(":cid" => $id); $items = Articles::model()->findAll($criteria); if (is_array($items) && count($items)) { foreach ($items as $item) { $checked = BannersPagesRelation::model()->findByAttributes(array("banner_id" => $bid, "object_id" => $item->id, "model" => $model)) ? true : false; $result[] = array('name' => $item->name, 'model' => $model, 'id' => $item->id, 'oid' => $item->id, 'isParent' => $isParent, "checked" => $checked); } } break; case 'clinics': $criteria->addCondition("is_active = 1"); $criteria->limit = $limit; $criteria->offset = $p * $limit; $items = Clinics::model()->findAll($criteria); if (is_array($items) && count($items)) { foreach ($items as $item) { $checked = BannersPagesRelation::model()->findByAttributes(array("banner_id" => $bid, "object_id" => $item->id, "model" => $model)) ? true : false; $result[] = array('name' => $item->name, 'model' => $model, 'id' => $item->id, 'oid' => $item->id, 'isParent' => $isParent, "checked" => $checked); } } break; case 'experts': $criteria->addCondition("is_active = 1"); $criteria->limit = $limit; $criteria->offset = $p * $limit; $items = Experts::model()->findAll($criteria); if (is_array($items) && count($items)) { foreach ($items as $item) { $checked = BannersPagesRelation::model()->findByAttributes(array("banner_id" => $bid, "object_id" => $item->id, "model" => $model)) ? true : false; $result[] = array('name' => $item->name, 'model' => $model, 'id' => $item->id, 'oid' => $item->id, 'isParent' => $isParent, "checked" => $checked); } } break; case 'book_categories': $criteria->addCondition("is_active = 1"); $criteria->limit = $limit; $criteria->offset = $p * $limit; $items = BookCategories::model()->findAll($criteria); if ($id == 0) { $isParent = true; $model = 'book'; } if (is_array($items) && count($items)) { foreach ($items as $item) { $criteria = new CDbCriteria(); $criteria->addCondition("category_id = :cid AND is_active = 1"); $criteria->params = array(":cid" => $item->id); $count = BookPages::model()->count($criteria); $checked = BannersPagesRelation::model()->findByAttributes(array("banner_id" => $bid, "object_id" => $item->id, "model" => $model)) ? true : false; $result[] = array('name' => $item->name, 'model' => $model, 'id' => $item->id, 'oid' => $item->id, 'count' => $count, 'page' => $p, 'pageSize' => 30, 'isParent' => $isParent, "checked" => $checked); } } break; case 'book': $criteria->addCondition("category_id = :cid AND is_active = 1"); $criteria->limit = $limit; $criteria->offset = $p * $limit; $criteria->params = array(":cid" => $id); $items = BookPages::model()->findAll($criteria); if (is_array($items) && count($items)) { foreach ($items as $item) { $checked = BannersPagesRelation::model()->findByAttributes(array("banner_id" => $bid, "object_id" => $item->id, "model" => $model)) ? true : false; $result[] = array('name' => $item->name, 'model' => $model, 'id' => $item->id, 'oid' => $item->id, 'isParent' => $isParent, "checked" => $checked); } } break; } } echo json_encode($result); }