예제 #1
0
 public function __construct($attributes = array(), $deep = false)
 {
     parent::__construct($attributes, $deep);
     $query = Query::build()->select('tag')->from('itemTags')->where('item', '=', 'item', true)->bind('item', $this->id)->get();
     $tags = array();
     foreach ($query as $row) {
         if ($deep) {
             $tags[] = tags::model()->getByPK($row['tag']);
         } else {
             $tags[] = $row['tag'];
         }
     }
     $this->attributes['tags'] = $tags;
 }
예제 #2
0
 /**
  * Allows the user to make changes to an existing product
  * 
  * If data has been posted, an attempt will be made to save the changes to the database.  The user
  * will then be redirected to the product view with a notification whether the changes were saved
  * or not.  If no data has been posted, the method will attempt to render a form with the editable
  * fields for the product indicated via ID in the query string.  If no ID is given in the query string
  * or if a product matching that ID cannot be found in the database, the user will be redirected to the
  * product index.
  */
 public function actionEdit()
 {
     if (isset($_POST['model'])) {
         //check that data has been posted
         $model = items::model()->getByPK($_POST['model']['id']);
         $model->setAttributes($_POST['model']);
         if ($model->save()) {
             //set the alert based on success of the save
             testProject::setAlert('The changes were saved successfully.', 'success');
             $this->redirect("items/view/{$model->id}");
         } else {
             testProject::setAlert('We\'re sorry but your changes were not saved.  Please try again.', 'danger');
             $this->redirect("items/view/{$model->id}");
         }
         //redirect to product view
         $this->redirect('items/view/' . $model->id);
     } else {
         //if no data is posted
         if (isset($_GET['value'])) {
             //attempt to load record based on ID and render edit form
             $model = items::model()->getByPK($_GET['value']);
             $statuses = statuses::model()->getAll();
             $vendors = vendors::model()->getAll();
             $tags = tags::model()->getAll();
             $this->render('edit', array('model' => $model, 'statuses' => $statuses, 'vendors' => $vendors, 'tags' => $tags));
         } else {
             //if no record found, redirect to product index
             $this->redirect('items');
         }
     }
 }
예제 #3
0
 /**
  * Deletes a tag
  * 
  * If no tag ID is passed or if it does not match a valid product ID in the database, an error
  * message is generated.  Otherwise the tag is deleted and a success message is generated.  In either
  * case the user is redirected to the tags index.
  */
 public function actionDelete()
 {
     testProject::setAlert('There was a problem with your request.  Please try again.', 'error');
     if (isset($_GET['value'])) {
         $model = tags::model()->getByPK($_GET['value']);
         $name = $model->name;
         if ($model->delete()) {
             testProject::setAlert('The item ' . $name . ' was deleted.', 'info');
         }
     }
     $this->redirect('tags/index');
 }