public function run() { $ids = array_reverse(Yii::app()->{$this->_type}->getPositions()); $totalCount = count($ids); $criteria = new CDbCriteria(); $criteria->addInCondition('t.id', $ids); if (!empty($ids)) { $criteria->order = 'FIELD(t.id, ' . implode(',', $ids) . ')'; } $collections = Collection::model()->published()->with('series:published')->findAll(); foreach ($collections as $collectionKey => &$collection) { $seriesArr = $collection->series; foreach ($seriesArr as $seriesKey => $series) { $series->goods = Good::model()->published()->series($series->id)->findAll($criteria); if (empty($series->goods)) { unset($seriesArr[$seriesKey]); } } $collection->series = $seriesArr; if (empty($collection->series)) { unset($collections[$collectionKey]); } } $this->render($this->view, array('collections' => $collections)); }
public function loadModel($id) { if (($model = Collection::model()->findByPk($id)) === null) { throw new CHttpException(404, 'Страница не найдена'); } return $model; }
public function run() { $this->collectionId = (int) $this->collectionId; $collection = Collection::model()->published()->with(array('series' => array('scopes' => array('published'), 'order' => 'series.sort ASC')))->findByPk($this->collectionId); if (!$collection) { return; } $this->render($this->view, array('collection' => $collection, 'title' => $this->title, 'seriesView' => $this->seriesView)); }
public function actionCollection($alias) { $collection = Collection::model()->published()->with(array('slides' => array('scopes' => 'published', 'order' => 'slides.sort ASC'), 'series' => array('scopes' => 'published', 'order' => 'series.sort ASC')))->find('t.alias = :alias', array(':alias' => $alias)); if (!$collection) { throw new CHttpException(404); } $this->currentCollection = $collection; $this->render('collection', array('model' => $collection)); }
public function actionIndex() { $needing_id = $_GET['id']; //需求不复杂使用ar //需求复杂可用dao(cdbcommand) //查询条件多用cdbcreteria类 $needing = new Needing(); $info = $needing->find('id=:id', array(':id' => $needing_id)); //收藏 $collection = Collection::model()->count('user_id=:user_id and needing_id=:cat_id', array(':user_id' => Yii::app()->user->id, ':cat_id' => $needing_id)); //验证是否已参与需求 $needing_gotAll = NeedingPre::model()->findAll('needing_id=:needing_id', array(':needing_id' => $needing_id)); $needing_gotCheck = NeedingPre::model()->count('needing_id=:needing_id and username=:username', array(':needing_id' => $needing_id, ':username' => Yii::app()->user->name)); //需求是否已托管 $needing_tuoguan = NeedingGet::model()->find('needing_id=:needing_id', array(':needing_id' => $needing_id)); $this->render('index', array('needing' => $info, 'collect_num' => $collection, 'needing_got' => $needing_gotCheck, 'needing_gotAll' => $needing_gotAll, 'needing_tuoguan' => $needing_tuoguan, 'needing_reply' => '')); }
public function findByAlias() { return Collection::model()->findByAttributes(array('alias' => $this->alias)); }
public function getCollectionList() { return CHtml::listData(Collection::model()->findAll(), 'id', 'title'); }
private function newAlbum() { //check if this is an album or collection //will also check if is a legall request, and if isn't, will throw an exception and stop $isCollection = self::isCollection(); $models = $isCollection ? Collection::model()->findAll() : Album::model()->findAll(); //if we haven't set a pid manually, we will set first free pid if (!$this->pid) { $max = 0; for ($i = 0; $i < 2; $i++) { $testmodel = $i === 0 ? new Album() : new Collection(); $criteria = new CDbCriteria(); $criteria->select = 'max(pid) AS pid'; $row = $testmodel->model()->find($criteria); $max = $max < $row['pid'] ? $row['pid'] : $max; } //if is first created albums or collections, we set $this->pid to 1; $this->pid = $max ? (int) $max + 1 : 1; $max; } $arrModelsNames = array(); foreach ($models as $m => $detail) { $trs = unserialize($detail['translations']); $name = $trs['name'][$this->lang->default]; $arrModelsNames[] = $name; } $modelNameTranslations = array(); $modelDescriptionTranslations = array(); $albumName = ''; foreach ($this->lang->all as $key => $language) { $name = self::purifiedTtext($_POST['newAlbumName_' . $language]); $name = $name ? $name : $this->tr('noName'); $description = self::purifiedTtext($_POST['newAlbumDescription_' . $language]); $description = $description ? $description : $this->tr('noDescription'); if (count($arrModelsNames)) { $p = explode(' ', $name); $last = $p[count($p) - 1]; $name = is_numeric($last) ? self::firstFreeNameIndex($arrModelsNames, $name, $last) : ($name = self::firstFreeNameIndex($arrModelsNames, $name)); } $modelNameTranslations[$language] = $name; $modelDescriptionTranslations[$language] = $description; $albumName .= ' ' . strtolower($name); } $translationsArr = array('name' => $modelNameTranslations, 'description' => $modelDescriptionTranslations); $model = $isCollection ? new Collection() : new Album(); $model->pid = $this->pid; $model->url = $this->getUrlRouteStructure(); $model->translations = serialize($translationsArr); $model->author = Yii::app()->user->name; $model->tags = self::tags($albumName); if (!$model->save()) { throw new Exception('fbgallery - newAlbum - ' . $this->tr('cantSave')); } else { if (!isset($_POST['isCollection'])) { self::createFoldersStructure(); } } }
public function run() { $budget = Collection::model()->findAllByAttributes(array('type' => Collection::BUDGET)); $this->render('actionbar', array('budget' => $budget)); }
protected function getInfo($from, $pid, $infoType) { $model = $from === 'album' ? Album::model()->find(array('condition' => "pid='{$pid}'")) : Collection::model()->find(array('condition' => "pid='{$pid}'")); $trs = unserialize($model->translations); $info = $trs[$infoType][$this->lang->active]; if (!$info) { $info = $trs[$infoType][$this->lang->default]; } return $info; }
protected function setPid() { //step 1: //create standard url using actual url $thisUrl = $this->getUrlRouteStructure(); //chech if page is album //compare actual url route with routes from Album model $album = Album::model()->find(array('condition' => "url='{$thisUrl}'")); if ($album) { $this->pid = $album->pid; return; } //chech if page is collection $collection = Collection::model()->find(array('condition' => "url='{$thisUrl}'")); if ($collection) { $this->pid = $collection->pid; return; } //there isn't any album or collection for this page //if is visitor, there isn't necessary to generate next pid, we set it to 0; if (!$this->levelAccess) { $this->pid = 0; return; } }