Пример #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new View();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['View'])) {
         $model->attributes = $_POST['View'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id_view));
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function actionAdd()
 {
     if (isset($_POST['img'])) {
         //INSERT
         $mod = new View();
         $mod->uid = Yii::app()->user->id;
         $mod->photo = $_POST['img'];
         if ($mod->save()) {
             return true;
         } else {
             return false;
         }
     } else {
         echo 'false';
     }
 }
Пример #3
0
 public function preFilter($filter_chain)
 {
     if (is_null($this->model_id)) {
         throw new CException('Required model_id attribute!');
     }
     if (!Yii::app()->user->isGuest && ($id = Yii::app()->request->getParam('id'))) {
         $attributes = array('user_id' => Yii::app()->user->id, 'object_id' => $id, 'model_id' => $this->model_id);
         $exist = View::model()->existsByAttributes($attributes);
         if (!$exist) {
             $view = new View();
             $view->attributes = $attributes;
             if (!$view->save()) {
                 throw new CException("Can't save views");
             }
         }
     }
     return true;
 }
Пример #4
0
 public function actionAViews()
 {
     $views = new View();
     $Vs = View::model()->findAll();
     if (isset($_POST['View'])) {
         $views->attributes = $_POST['View'];
         if ($views->save()) {
             $this->redirect(array('lviews', 'fitback' => 4));
         }
     }
     $this->render('aviews', array('views' => $views, 'Vs' => $Vs));
 }
Пример #5
0
 public function __actionEdit()
 {
     if ($this->_context[0] != 'new' && strlen(trim($this->_context[1])) == 0) {
         redirect(ADMIN_URL . '/blueprints/views/');
     }
     $context = $this->_context;
     array_shift($context);
     $view_pathname = implode('/', $context);
     if (array_key_exists('delete', $_POST['action'])) {
         $this->__actionDelete(array($view_pathname), ADMIN_URL . '/blueprints/views/');
     } elseif (array_key_exists('save', $_POST['action'])) {
         $fields = $_POST['fields'];
         $fields['types'] = preg_split('/\\s*,\\s*/', $fields['types'], -1, PREG_SPLIT_NO_EMPTY);
         if (strlen(trim($fields['url-parameters'])) > 0) {
             $fields['url-parameters'] = preg_split('/\\/+/', trim($fields['url-parameters'], '/'), -1, PREG_SPLIT_NO_EMPTY);
         }
         if (strlen(trim($fields['handle'])) == 0) {
             $fields['handle'] = Lang::createHandle($fields['title']);
         }
         $path = trim($fields['parent'] . '/' . $fields['handle'], '/');
         if ($this->_context[0] == 'edit') {
             $view = self::__loadExistingView($view_pathname);
             $view->types = $fields['types'];
             $view->title = $fields['title'];
             $view->{'data-sources'} = $fields['data-sources'];
             $view->events = isset($fields['events']) ? $fields['events'] : array();
             $view->{'url-parameters'} = $fields['url-parameters'];
             // Path has changed - Need to move the existing one, then save it
             if ($view->path != $path) {
                 $this->errors = new MessageStack();
                 try {
                     // Before moving or renaming, simulate saving to check for potential errors
                     View::save($view, $this->errors, true);
                     View::move($view, $path);
                 } catch (Exception $e) {
                     // Saving failed, catch it further down
                 }
             }
         } else {
             $view = View::loadFromFieldsArray($fields);
             $view->template = file_get_contents(TEMPLATES . '/template.view.txt');
             $view->handle = $fields['handle'];
             $view->path = $path;
         }
         $this->errors = new MessageStack();
         try {
             View::save($view, $this->errors);
             redirect(ADMIN_URL . '/blueprints/views/edit/' . $view->path . '/:saved/');
         } catch (ViewException $e) {
             switch ($e->getCode()) {
                 case View::ERROR_MISSING_OR_INVALID_FIELDS:
                     $this->alerts()->append(__('An error occurred while processing this form. <a href="#error">See below for details.</a>'), AlertStack::ERROR, $this->errors);
                     break;
                 case View::ERROR_FAILED_TO_WRITE:
                     $this->alerts()->append($e->getMessage(), AlertStack::ERROR, $e);
                     break;
             }
         } catch (Exception $e) {
             // Errors!!
             // Not sure what happened!!
             $this->alerts()->append(__('An unknown error has occurred. <a class="more">Show trace information.</a>'), AlertStack::ERROR, $e);
         }
     }
 }
Пример #6
0
		public static function add($userid, $itemid)
		{
			$vw = new View(null, $userid, $itemid, time());
			return $vw->save();
		}