Пример #1
0
 /**
  * Get additional content data selected
  * 
  * @param $result = Query result
  */
 public static function post_find($result)
 {
     if ($result !== null) {
         if (is_array($result)) {
             foreach ($result as $item) {
                 // It will first check if we already have result in temporary result,
                 // and only execute query if we dont. That way we dont have duplicate queries
                 // Get group attributes
                 $item->get_attributes = static::lazy_load(function () use($item) {
                     $attributes = Model_Attribute_To_Groups::find(function ($query) use($item) {
                         return $query->where('group_id', $item->id);
                     }, 'attribute_id');
                     if (!empty($attributes)) {
                         $attributes = '(' . implode(',', array_keys($attributes)) . ')';
                         return Model_Attribute::find(function ($query) use($attributes) {
                             return $query->where('id', 'IN', \DB::expr($attributes))->order_by('sort', 'asc');
                         }, 'id');
                     }
                     return array();
                 }, $item->id, 'attributes');
             }
         }
     }
     // return the result
     return $result;
 }
Пример #2
0
 public function action_delete($id = false)
 {
     if (is_numeric($id)) {
         // Get news item to edit
         if ($item = Model_Attribute_Group::find_one_by_id($id)) {
             // Delete item
             try {
                 // Delete relation to attributes
                 $attributes = Model_Attribute_To_Groups::find_by_group_id($item->id);
                 if (!is_null($attributes)) {
                     foreach ($attributes as $attribute) {
                         $attribute->delete();
                     }
                 }
                 $item->delete();
                 \Messages::success('Attribute group successfully deleted.');
             } catch (\Database_Exception $e) {
                 // show validation errors
                 \Messages::error('<strong>There was an error while trying to delete attribute group</strong>');
                 // Uncomment lines below to show database errors
                 //$errors = $e->getMessage();
                 //\Messages::error($errors);
             }
         }
     }
     \Response::redirect(\Input::referrer(\Uri::create('admin/attribute/group/list')));
 }