Backend\Modules\Faq\Engine\Model::update PHP Method

update() public static method

Update a certain question
public static update ( array $item )
$item array
    public static function update(array $item)
    {
        BackendModel::getContainer()->get('database')->update('faq_questions', $item, 'id = ?', array((int) $item['id']));
    }

Usage Example

Example #1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     $questionId = \SpoonFilter::getPostValue('questionId', null, '', 'int');
     $fromCategoryId = \SpoonFilter::getPostValue('fromCategoryId', null, '', 'int');
     $toCategoryId = \SpoonFilter::getPostValue('toCategoryId', null, '', 'int');
     $fromCategorySequence = \SpoonFilter::getPostValue('fromCategorySequence', null, '', 'string');
     $toCategorySequence = \SpoonFilter::getPostValue('toCategorySequence', null, '', 'string');
     // invalid question id
     if (!BackendFaqModel::exists($questionId)) {
         $this->output(self::BAD_REQUEST, null, 'question does not exist');
     } else {
         // list ids
         $fromCategorySequence = (array) explode(',', ltrim($fromCategorySequence, ','));
         $toCategorySequence = (array) explode(',', ltrim($toCategorySequence, ','));
         // is the question moved to a new category?
         if ($fromCategoryId != $toCategoryId) {
             $item['id'] = $questionId;
             $item['category_id'] = $toCategoryId;
             BackendFaqModel::update($item);
             // loop id's and set new sequence
             foreach ($toCategorySequence as $i => $id) {
                 $item = array();
                 $item['id'] = (int) $id;
                 $item['sequence'] = $i + 1;
                 // update sequence if the item exists
                 if (BackendFaqModel::exists($item['id'])) {
                     BackendFaqModel::update($item);
                 }
             }
         }
         // loop id's and set new sequence
         foreach ($fromCategorySequence as $i => $id) {
             $item['id'] = (int) $id;
             $item['sequence'] = $i + 1;
             // update sequence if the item exists
             if (BackendFaqModel::exists($item['id'])) {
                 BackendFaqModel::update($item);
             }
         }
         // success output
         $this->output(self::OK, null, 'sequence updated');
     }
 }
All Usage Examples Of Backend\Modules\Faq\Engine\Model::update