protected function afterDelete()
 {
     parent::afterDelete();
     // If a category is deleted, remove it from any nested 'categories' documents
     /*
      * $id = $this->id; $model = \Shop\Admin\Models\Products::instance(); $collection = $model->getCollection(); $result = $collection->update( array('metadata.categories.id' => $id ), array( '$pull' => array( 'metadata.categories' => array( 'id' => $id ) ) ), array( 'multiple' => true ) );
      */
 }
Exemple #2
0
 protected function afterSave()
 {
     if (count($this->__list_permissions)) {
         $acl = \Dsc\System::instance()->get('acl')->getAcl();
         foreach ($this->__list_permissions as $resource => $actions) {
             foreach ($actions as $action => $val) {
                 if ((int) $val == 1) {
                     $acl->allow($this->slug, $resource, $action);
                 } else {
                     $acl->deny($this->slug, $resource, $action);
                 }
             }
         }
     }
     return parent::afterSave();
 }
Exemple #3
0
 /**
  * 
  * @return \MongoId
  */
 protected function afterSave()
 {
     // if a CSV of product_ids has been bound to the model, update the set of products associated with this category
     if (!empty($this->__products)) {
         if (!is_array($this->__products)) {
             $this->__products = trim($this->__products);
             if (!empty($this->__products)) {
                 $this->__products = \Base::instance()->split((string) $this->__products);
             }
         }
         if (!empty($this->__products) && is_array($this->__products)) {
             // convert the array of product ids into an array of MongoIds
             $this->__products = array_map(function ($input) {
                 return new \MongoId($input);
             }, $this->__products);
             // TODO Update this to include "path" when we make that update
             $category = array('id' => new \MongoId((string) $this->id), 'title' => $this->title, 'slug' => $this->slug);
             $category_id = new \MongoId((string) $this->id);
             // OK, we have an array of product MongoIDs. Now make two queries:
             // 1. Add this category to all products whose ID is in this array
             $add_result = (new \Shop\Models\Products())->collection()->update(array('_id' => array('$in' => $this->__products)), array('$addToSet' => array('categories' => $category)), array('multiple' => true));
             // 2. Remove this category from all products whose ID is not in this array
             $remove_result = (new \Shop\Models\Products())->collection()->update(array('_id' => array('$nin' => $this->__products), 'categories.id' => $category_id), array('$pull' => array('categories' => array('id' => $category_id))), array('multiple' => true));
         }
         unset($this->__products);
     }
     return parent::afterSave();
 }