Пример #1
0
    public function actionIndex() {

    	$this->active_link = 'dashboard';
    	//count users
    	$users = User::model()->count('status != '.User::STATUS_DELETED);
        $objects = Objects::model()->active()->count(array('select'=>'id'));
        $objectsNew = Objects::model()->active()->count(array('select'=>'id','condition'=>'verified = false'));
        $polls = PollChoice::model()->count();
        $photos = ObjectsImages::model()->count();
        $videos = ObjectsHttp::model()->count(array('condition'=>'type='.ObjectsHttp::TYPE_VIDEO));
        $this->render('dashboard',array('users'=>$users,'objects'=>$objects,
            'objectsNew'=>$objectsNew, 'polls'=>$polls,'photos'=>$photos,
            'videos'=>$videos

        ));
    }
Пример #2
0
 	public function setHttp(array $http, array $http_comments, $add = false, $type = ObjectsHttp::TYPE_LINK)
	{
        $errors = array();      
        $dontDelete = array();
        if(!empty($http)){ // массив http . Обычно есть хоть одна пустая строка
		foreach($http as $k=>$c){
			$c = trim(strip_tags($c));
			if(empty($c))
				continue;
			$found = ObjectsHttp::model()->findByAttributes(array(
				'site'=>$c,
				'object'=>$this->id,
				'type'=>$type
			));
			// если не было email - делаем
			if(!$found){
				$record = new ObjectsHttp;
				$record->site = $c;
				if(isset($http_comments[$k]))
					$record->description = $http_comments[$k];
				if(!Yii::app()->user->isGuest){
					$record->user_id = Yii::app()->user->id;
				}
				$record->object = $this->id;
				$record->type = $type;
				if($record->save()){
					$dontDelete[] = $record->id;
				} else {
					$errors['email'] = $c;
					$errors['error'] = $record->errors;
				}           
			} else { // обновляем описание
				$dontDelete[] = $found->id;
				if(isset($http_comments[$k])){
					$fk = trim(strip_tags($http_comments[$k]));
					if($found->description != $fk){
						$found->description = $fk;
						$found->save(true, array('description'));
						if(!$found->save(true,array('description'))){

						}
					}
				}
			}
		}
		}
		if($add === false){
			// Удаляем все категории, которых не было в массиве
			if(sizeof($dontDelete) > 0){
				$cr = new CDbCriteria;
				$cr->addNotInCondition('id', $dontDelete);

				ObjectsHttp::model()->deleteAllByAttributes(array(
					'object'=>$this->id,
					'type'=>$type
				), $cr);
			} else { // удаляем все телефоны, т.к. пустой массив
				// Delete all relations
				ObjectsHttp::model()->deleteAllByAttributes(array(
					'object'=>$this->id,
					'type'=>$type
				));
			}  
		}
		if(!empty($errors))
			return $errors;
		else
			return true;
	}