Example #1
0
 /**
  * Process category contents
  *
  * @param  array $post
  * @return void
  */
 public function process(array $post)
 {
     foreach ($post as $key => $value) {
         if (substr($key, 0, 6) == 'order_') {
             $key = substr($key, strpos($key, '_') + 1);
             $orderAry = explode('_', $key);
             $catItem = $orderAry[0] == 'media' ? Table\CategoryMedia::findById([(int) $post['category_id'], (int) $orderAry[1]]) : Table\CategoryContent::findById([(int) $post['category_id'], (int) $orderAry[1]]);
             if (isset($catItem->category_id)) {
                 $catItem->order = (int) $value;
                 $catItem->save();
             }
         }
     }
     if (isset($post['rm_category_items'])) {
         foreach ($post['rm_category_items'] as $item) {
             $idAry = explode('_', $item);
             $catItem = $idAry[0] == 'media' ? Table\CategoryMedia::findById([(int) $post['category_id'], (int) $idAry[1]]) : Table\CategoryContent::findById([(int) $post['category_id'], (int) $idAry[1]]);
             if (isset($catItem->category_id)) {
                 $catItem->delete();
             }
         }
     }
 }
Example #2
0
 /**
  * Get all category values for the form object
  *
  * @param  AbstractController $controller
  * @param  Application        $application
  * @return void
  */
 public static function getAll(AbstractController $controller, Application $application)
 {
     if (!$_POST && $controller->hasView() && null !== $controller->view()->form && $controller->view()->form !== false && (int) $controller->view()->form->id != 0 && null !== $controller->view()->form && $controller->view()->form instanceof \Pop\Form\Form) {
         $type = $controller->view()->form->category_type;
         $contentId = $controller->view()->form->id;
         $values = [];
         if (null !== $type) {
             $catItems = $type == 'media' ? Table\CategoryMedia::findBy(['media_id' => $contentId]) : Table\CategoryContent::findBy(['content_id' => $contentId]);
             if ($catItems->hasRows()) {
                 foreach ($catItems->rows() as $c) {
                     $values[] = $c->category_id;
                 }
             }
         }
         if (count($values) > 0) {
             $controller->view()->form->categories = $values;
         }
     }
 }