Exemplo n.º 1
0
 /**
  * Returns the active entry or null if there is no active entry.
  * @return Entry || null
  */
 public function getActiveEntry()
 {
     if ($this->_activeEntryId === null) {
         return null;
     }
     return Entry::model()->findByPk($this->_activeEntryId, 'deleted=0');
 }
Exemplo n.º 2
0
 /**
  * (non-PHPdoc)
  * @see yii/CWidget#run()
  */
 public function run()
 {
     // criteria for last entries
     $c = new CDbCriteria();
     $c->order = 't.viewCount DESC';
     $c->limit = Setting::model()->name(Setting::MOST_VIEWED_ENTRIES_WIDGET_COUNT)->find()->value;
     // get entries
     $models = Entry::model()->findAll($c);
     // render view
     $this->render('mostViewed', array('models' => $models));
 }
Exemplo n.º 3
0
 /**
  *
  * @return void
  */
 public function actionCsv()
 {
     Yii::import('ext.ECSVExport');
     $data = array();
     foreach (Entry::model()->findAllByAttributes(array('userId' => Yii::app()->user->id)) as $model) {
         /* @var Entry $model */
         $data[] = array('name' => $model->name, 'url' => $model->url, 'comment' => $model->comment, 'tags' => $model->tagList, 'username' => $model->username, 'password' => $model->password);
     }
     $csv = new ECSVExport($data);
     Yii::app()->request->sendFile(sprintf('ppma-export-%s', date('YmdHis')), $csv->toCSV(), 'text/csv', false);
 }
Exemplo n.º 4
0
    public function run()
    {
        // criteria for last entries
        $c = new CDbCriteria();
        $c->order = 't.id DESC';
        /** @noinspection PhpUndefinedMethodInspection */
        $c->limit = Setting::model()->name(Setting::RECENT_ENTRIES_WIDGET_COUNT)->find()->value;

        // get entries
        $models = Entry::model()->findAll($c);

        // render view
        $this->render('recent', array('models' => $models));
    }
Exemplo n.º 5
0
 /**
  * @param string $term
  */
 public function actionSearchName($term)
 {
     // escape $term
     $term = CPropertyValue::ensureString($term);
     // create criteria
     $c = new CDbCriteria();
     $c->distinct = true;
     $c->addSearchCondition('name', $term);
     $c->limit = 5;
     // save results
     $result = array();
     foreach (Entry::model()->findAll($c) as $model) {
         /* @var Entry $model */
         $result[] = $model->name;
     }
     // output result as JSON
     echo CJSON::encode($result);
 }
Exemplo n.º 6
0
 private function renderProfileDetail($model)
 {
     //        $roles = Yii::app()->authManager->getRoles($model->getPrimaryKey());
     $role = $model->role;
     if (!empty($role)) {
         if ($role == 'admin' || $role == 'teacher') {
             $criteria = new CDbCriteria();
             $criteria->order = 'created_date DESC';
             $criteria->condition = 'owner_by = :owner_by';
             $criteria->params = array(':owner_by' => $model->getPrimaryKey());
             $count = Entry::model()->count($criteria);
             $pages = new CPagination($count);
             // results per page
             $pages->pageSize = Yii::app()->params['entriesPerPage'];
             $pages->applyLimit($criteria);
             $entries = Entry::model()->findAll($criteria);
             $dataRender = array('model' => $model, 'entries' => $entries, 'pages' => $pages);
             if ($this->getRoute() == 'account/update') {
                 $dataRender['mode'] = 'edit';
             }
             $this->render('view_teacher', $dataRender);
         } elseif ($role == 'student') {
             $dataRender = array('model' => $model);
             if ($this->getRoute() == 'account/update') {
                 $dataRender['mode'] = 'edit';
             }
             $this->render('view_student', $dataRender);
         } else {
             $dataRender = array('model' => $model);
             if ($this->getRoute() == 'account/update') {
                 $dataRender['mode'] = 'edit';
             }
             $this->render('view_user', $dataRender);
         }
     }
 }
Exemplo n.º 7
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $count = isset($_POST['entryCount']) ? intval($_POST['entryCount']) : 0;
     if (isset($_POST['Invoice'])) {
         $model->attributes = $_POST['Invoice'];
         for ($i = 0; $i < $count; $i++) {
             //$item = new Item;
             //$item->attributes = $_POST["Item$i"];
             //$pk = $item->id;
             $_item = Entry::model()->findByPk(intval($_POST["Entry{$i}" . "_id"]));
             $_item->attributes = $_POST["Entry{$i}"];
             $_item->save();
         }
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('update', array('model' => $model, 'entries' => $model->Entries));
 }
Exemplo n.º 8
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Entry::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Exemplo n.º 9
0
    /**
     * @param int $id
     * @return Entry
     * @throws CHttpException
     */
    protected function loadModel($id)
    {
        $model = Entry::model()->findbyPk($id);

        if ($model === null) {
            throw new CHttpException(404);
        } elseif ($model->userId != Yii::app()->user->id) {
            throw new CHttpException(403);
        }

        return $model;
    }