Пример #1
0
 public function actionDefault($params)
 {
     $topic = new Model_Topic($this->getStorage());
     $group = new Model_Group($this->getStorage());
     $topic->regenerate();
     $group->regenerate();
 }
Пример #2
0
 public function selectGroup($name, $value = null, $attribs = null, $currentGroup = null, $exclude = null, $excludeCurrent = true)
 {
     $mdlGroup = new Model_Group();
     $groups = $mdlGroup->getGroupNamesArray($exclude);
     $options[] = $this->view->getTranslation('Select Group');
     if (count($groups) > 0) {
         foreach ($groups as $group) {
             if (false == $excludeCurrent || (empty($currentGroup) || $group['name'] != $currentGroup)) {
                 if (isset($group['label']) && !empty($group['label'])) {
                     $options[$group['name']] = $group['label'];
                 } else {
                     $options[$group['name']] = $group['name'];
                 }
             }
         }
     }
     $form = new Digitalus_Form();
     $select = $form->createElement('select', $name, array('multiOptions' => $options));
     if (is_array($value)) {
         $select->setValue($value);
     }
     if (is_array($attribs)) {
         $select->setAttribs($attribs);
     }
     return $select;
 }
Пример #3
0
 function init()
 {
     parent::init();
     $this->addExpression('OpeningBalanceDr')->set(function ($m, $q) {
         $ledger = $m->add('xepan\\accounts\\Model_Ledger');
         return $ledger->addCondition('group_path', 'like', $q->expr('CONCAT([0],"%")', [$q->getField('path')]))->sum($q->expr('IFNULL([0],0)', [$ledger->getElement('OpeningBalanceDr')]));
     });
     $this->addExpression('OpeningBalanceCr')->set(function ($m, $q) {
         $ledger = $m->add('xepan\\accounts\\Model_Ledger');
         return $ledger->addCondition('group_path', 'like', $q->expr('CONCAT([0],"%")', [$q->getField('path')]))->sum($q->expr('IFNULL([0],0)', [$ledger->getElement('OpeningBalanceCr')]));
     });
     $this->addExpression('PreviousTransactionsDr')->set(function ($m, $q) {
         $transaction = $m->add('xepan\\accounts\\Model_TransactionRow');
         return $transaction->addCondition('group_path', 'like', $q->expr('CONCAT([0],"%")', [$q->getField('path')]))->addCondition('created_at', '<', $this->from_date)->sum($q->expr('IFNULL([0],0)', [$transaction->getElement('amountDr')]));
     });
     $this->addExpression('PreviousTransactionsCr')->set(function ($m, $q) {
         $transaction = $m->add('xepan\\accounts\\Model_TransactionRow');
         return $transaction->addCondition('group_path', 'like', $q->expr('CONCAT([0],"%")', [$q->getField('path')]))->addCondition('created_at', '<', $this->from_date)->sum($q->expr('IFNULL([0],0)', [$transaction->getElement('amountCr')]));
     });
     $this->addExpression('TransactionsDr')->set(function ($m, $q) {
         $transaction = $m->add('xepan\\accounts\\Model_TransactionRow');
         return $transaction->addCondition('group_path', 'like', $q->expr('CONCAT([0],"%")', [$q->getField('path')]))->addCondition('created_at', '>=', $this->from_date)->addCondition('created_at', '<', $this->app->nextDate($this->to_date))->sum($q->expr('IFNULL([0],0)', [$transaction->getElement('amountDr')]));
     });
     $this->addExpression('TransactionsCr')->set(function ($m, $q) {
         $transaction = $m->add('xepan\\accounts\\Model_TransactionRow');
         return $transaction->addCondition('group_path', 'like', $q->expr('CONCAT([0],"%")', [$q->getField('path')]))->addCondition('created_at', '>=', $this->from_date)->addCondition('created_at', '<', $this->app->nextDate($this->to_date))->sum($q->expr('IFNULL([0],0)', [$transaction->getElement('amountCr')]));
     });
     $this->addExpression('ClosingBalanceDr')->set(function ($m, $q) {
         return $q->expr('IFNULL([0],0)+IFNULL([1],0)+IFNULL([2],0)', [$m->getElement('OpeningBalanceDr'), $m->getElement('PreviousTransactionsDr'), $m->getElement('TransactionsDr')]);
     });
     $this->addExpression('ClosingBalanceCr')->set(function ($m, $q) {
         return $q->expr('IFNULL([0],0)+IFNULL([1],0)+IFNULL([2],0)', [$m->getElement('OpeningBalanceCr'), $m->getElement('PreviousTransactionsCr'), $m->getElement('TransactionsCr')]);
     });
 }
Пример #4
0
 /**
  * Fetch by ID
  * @param string $id
  * @return boolean|array
  */
 public function fetchById($id = null)
 {
     if (is_null($id)) {
         $id = $this->getId();
     }
     if (is_null($id)) {
         return false;
     }
     $modelGroup = new Model_Group();
     $result = $modelGroup->selectGroupById($id);
     if ($result !== false) {
         $this->init($result);
         return $result;
     } else {
         return false;
     }
 }
Пример #5
0
 public function action_delete($id = null)
 {
     if (!is_null($id) and $gid = Model_Group::find($id)->delete()) {
         \Session::set_flash('success', 'Group #' . $id . ' has been deleted.');
     } else {
         \Session::set_flash('error', 'Could not delete group #' . $id);
     }
     \Response::redirect('groups');
 }
Пример #6
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 related products
                 $item->get_products = static::lazy_load(function () use($item) {
                     $products = Model_Product_To_Groups::find(function ($query) use($item) {
                         return $query->where('group_id', $item->id);
                     }, 'product_id');
                     if (!empty($products)) {
                         $products = '(' . implode(',', array_keys($products)) . ')';
                         return Model_Product::find(function ($query) use($products, $item) {
                             $query->where('id', 'IN', \DB::expr($products));
                             $query->order_by('sort', 'asc');
                             return $query;
                         }, 'id');
                     }
                     return array();
                 }, $item->id, 'products');
                 // Get content children
                 $item->get_children = static::lazy_load(function () use($item) {
                     return Model_Group::find(array('where' => array('parent_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'children');
                 // Get group images
                 $item->get_images = static::lazy_load(function () use($item) {
                     return Model_Group_Image::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'images');
                 // Get product groups
                 $item->get_product_groups = static::lazy_load(function () use($item) {
                     $product_groups = \Product\Model_Group::find_by_type('discount');
                     foreach ($product_groups as $product_group) {
                         $product_group->set_user_group_id($item->id);
                     }
                     return $product_groups;
                 }, $item->id, 'product_groups');
             }
         }
     }
     // return the result
     return $result;
 }
Пример #7
0
 public static function install()
 {
     //\Migrate::latest();
     // Insert the default settings and user groups
     echo "\nInserting defaults...";
     \DB::insert('settings')->columns(array('setting', 'value'))->values(array('title', 'LitePress'))->execute();
     \DB::insert('settings')->columns(array('setting', 'value'))->values(array('theme', 'default'))->execute();
     \DB::insert('settings')->columns(array('setting', 'value'))->values(array('validate_users', '0'))->execute();
     $groups = array(array('Admin', 1, 1, 1, 1, 1), array('Author', 0, 1, 1, 1, 1), array('Reader', 0, 0, 0, 0, 0), array('Validating', 0, 0, 0, 0, 0), array('Guest', 0, 0, 0, 0, 0));
     foreach ($groups as $group) {
         $row = \Model_Group::forge(array('name' => $group[0], 'is_admin' => $group[1], 'is_author' => $group[2], 'create_articles' => $group[3], 'edit_articles' => $group[4], 'delete_articles' => $group[5]));
         $row->save();
     }
     // Create an admin account
     echo "\nCreating admin account...";
     $admin_password = strtolower(substr(sha1(time() . rand(1, 100)), 0, 5));
     $admin = \Model_User::forge(array('name' => 'Admin', 'username' => 'Admin', 'password' => $admin_password, 'email' => '*****@*****.**', 'group_id' => 1));
     $admin->save();
     echo "\nAdmin account created,", "\nUsername: Admin\n", "Password: " . $admin_password;
 }
Пример #8
0
 /**
  * 
  * Building tree
  */
 public function action_index()
 {
     if ($_POST) {
         $val = \Validation::forge();
         $val->add_field('id', 'node id', 'required|min_length[1]|max_length[20]');
         $val->add_field('rel', 'node type', 'required|min_length[1]|max_length[20]');
         if ($val->run()) {
             switch ($this->gettype($val->validated('rel'))) {
                 //room
                 case 0:
                     $data['groups'] = Model_Group::find()->where('meta_update_user', $this->user)->get();
                     return \Response::forge(\View::forge('tree/group', $data));
                     break;
                     //group
                 //group
                 case 1:
                     $tests = Model_Test::find()->where('group_id', $val->validated('id'))->get();
                     $data['tests'] = $tests;
                     return \Response::forge(\View::forge('tree/test', $data));
                     break;
                     //test
                 //test
                 case 2:
                     $records = Model_Record::find()->where('test_id', $val->validated('id'))->get();
                     $data['records'] = $records;
                     return \Response::forge(\View::forge('tree/record', $data));
                     break;
                     //record
                 //record
                 case 3:
                     echo '{:P}';
                     break;
             }
             //echo $val->validated('id');
         }
     }
 }
Пример #9
0
 public function actionMove($params)
 {
     $view = $this->ajaxView('group');
     $view->state = "failed";
     if ($params["id"]) {
         $group = new Model_Group($this->getStorage(), $params["id"]);
         $view->id = $group->getId();
         $view->parent_id = (int) $params['targid'];
         if ($view->parent_id != 0) {
             $targGroup = new Model_Group($this->getStorage(), $params["targid"]);
             $view->parent_id = $targGroup->getId();
             if (!$view->parent_id) {
                 $this->error = "Target group not found.";
                 return $view;
             }
         }
         if ($view->id) {
             if ($view->id != $view->parent_id) {
                 $group->parent = $view->parent_id;
                 if ($errors = $group->validate()) {
                     $view->error = "validation failed";
                     $view->errors = $errors;
                 } else {
                     $view->state = "moved";
                     try {
                         $group->save();
                     } catch (Exception $e) {
                         $view->state = "failed";
                         $view->error = $e->getMessage();
                     }
                 }
             } else {
                 $view->state = "notmoved";
                 $view->error = "Group can't be root of itself.";
             }
         } else {
             $view->error = "Group(s) not found.";
         }
     } else {
         $view->error = "Group ID(s) are not set.";
     }
     return $view;
 }
Пример #10
0
 public function actionMove($params)
 {
     $view = $this->ajaxView('user');
     $view->state = "failed";
     if ($params["id"] && $params["targid"]) {
         $user = new Model_User($this->getStorage(), $params["id"]);
         $group = new Model_Group($this->getStorage(), $params["targid"]);
         $view->id = $user->getId();
         $view->group_id = $group->getId();
         if ($view->id && $view->group_id) {
             if ($user->group != $group->getId()) {
                 //$this->canPerform($article, "edit");
                 //$this->canPerform($topic, "edit");
                 $view->state = "moved";
                 $user->group = $group->getId();
                 try {
                     $user->save();
                 } catch (Exception $e) {
                     $view->state = "failed";
                     $view->error = $e->getMessage();
                 }
             } else {
                 $view->state = "notmoved";
             }
         } else {
             $view->error = "User or group not found.";
         }
     } else {
         $view->error = "User or group ID is not set.";
     }
     return $view;
 }
Пример #11
0
 public function get_search_items($category_id = false)
 {
     // Override category_id if its a search
     $category_id = \Input::get('category_id', $category_id);
     $product_ids = array();
     // If we are viewing category products
     // We need to find all products from that and child categories
     if (is_numeric($category_id)) {
         $category = \Product\Model_Category::find_one_by_id($category_id);
         if ($category) {
             \View::set_global('category', $category);
             if ($category->all_products) {
                 $product_ids = array_keys($category->all_products);
             }
         }
     }
     // If we are filtering products by category and there is nothing found
     // We return empty array of products without even going to database
     if (empty($product_ids) && is_numeric($category_id)) {
         $items = array();
     } else {
         /************ Start generating query ***********/
         $items = Model_Product::find(function ($query) use($product_ids) {
             if (!empty($product_ids)) {
                 $query->where('product.id', 'in', $product_ids);
             }
             // Get search filters
             foreach (\Input::get() as $key => $value) {
                 if (!empty($value) || $value == '0') {
                     switch ($key) {
                         case 'title':
                             $query->select('product.*');
                             $query->distinct();
                             $query->join('product_attributes');
                             $query->on('product.id', '=', 'product_attributes.product_id');
                             $query->where('product.' . $key, 'like', "%{$value}%");
                             // ->or_where('product.code', 'like', "%$value%")
                             //->or_where('product_attributes.product_code', 'like', "%$value%");
                             break;
                         case 'status':
                             if (is_numeric($value)) {
                                 $query->where($key, $value);
                             }
                             break;
                         case 'active_from':
                             $date = strtotime($value);
                             if ($date) {
                                 $query->where($key, '>=', $date);
                             }
                             break;
                         case 'active_to':
                             $date = strtotime($value);
                             if ($date) {
                                 $query->where($key, '<=', $date);
                             }
                             break;
                     }
                 }
             }
             // Order query
             $query->order_by('product.sort', 'asc');
             $query->order_by('product.id', 'asc');
         });
     }
     /************ End generating query ***********/
     // Reset to empty array if there are no result found by query
     if (is_null($items)) {
         $items = array();
     }
     // Initiate pagination
     $pagination = \Hybrid\Pagination::make(array('total_items' => count($items), 'per_page' => \Input::get('per_page', 10), 'uri_segment' => null));
     // Remove unwanted items, and show only required ones
     $items = array_slice($items, $pagination->offset, $pagination->per_page);
     $status = array('false' => 'Select', '1' => 'Active', '0' => 'Inactive', '2' => 'Active in period');
     $group = Model_Group::find();
     return array('items' => $items, 'group' => $group, 'pagination' => $pagination, 'status' => $status);
 }
Пример #12
0
 /**
  * adds roles dynamically from database
  */
 private function _addRoles()
 {
     // add role 'guest' and 'superadmin' explicitly
     $this->addRole(new Zend_Acl_Role(Model_Group::GUEST_ROLE));
     $this->addRole(new Zend_Acl_Role(Model_Group::SUPERUSER_ROLE));
     // add roles dynamically from database
     $mdlGroup = new Model_Group();
     $groups = $mdlGroup->getGroupNamesParentsArray();
     foreach ($groups as $group) {
         switch (strtolower($group['name'])) {
             case Model_Group::GUEST_ROLE:
             case Model_Group::SUPERUSER_ROLE:
                 break;
             default:
                 $this->addRole(new Zend_Acl_Role($group['name'], $group['parent']));
                 break;
         }
     }
 }
Пример #13
0
 /**
  * Special page
  * 
  * @access  public
  * @param   $slug
  */
 public function action_special($type = 'best-sellers')
 {
     $types = array('best-sellers' => 24, 'new-release' => 25, 'sale' => 26, 'popular-products' => 1);
     if (!isset($types[$type])) {
         throw new \HttpNotFoundException();
     }
     if (!($group = Model_Group::find_one_by_id($types[$type]))) {
         throw new \HttpNotFoundException();
     }
     if ($type == 'sale') {
         $products = Model_Product::find();
         foreach ($products as $key => $product) {
             if (empty($product->sale_price) || !reset($product->sale_price)->price > 0) {
                 unset($products[$key]);
             }
         }
     } else {
         $products = $group->products;
     }
     $items = $products;
     if ($items) {
         // Price range
         if (\Input::get('range')) {
             $range = explode('-', \Input::get('range'));
             $price_from = isset($range[0]) && is_numeric($range[0]) ? $range[0] : null;
             $price_to = isset($range[1]) && is_numeric($range[1]) ? $range[1] : null;
             if (!is_null($price_from) && !is_null($price_to)) {
                 foreach ($items as $key => $item) {
                     if ($item->default_price[0] >= $price_from && $item->default_price[0] <= $price_to) {
                         continue;
                     }
                     unset($items[$key]);
                 }
             }
         }
     }
     if ($items) {
         if (\Input::get('sort') == 'price_asc') {
             $items = \Product\Model_Product::get_sorted_products($items);
         } elseif (\Input::get('sort') == 'price_desc') {
             $items = array_reverse(\Product\Model_Product::get_sorted_products($items));
         }
     }
     // Reset to empty array if there are no result found by query
     if (is_null($items)) {
         $items = array();
     }
     // Initiate pagination
     $pagination = \Hybrid\Pagination::make(array('total_items' => count($items), 'per_page' => \Input::get('per_page', 12), 'uri_segment' => null));
     // Remove unwanted items, and show only required ones
     $items = array_slice($items, $pagination->offset, $pagination->per_page);
     \Theme::instance()->set_partial('content', $this->view_dir . 'special')->set('items', $items, false)->set('pagination', $pagination, false)->set('products', $products, false)->set('product_group', $group);
 }
Пример #14
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 related products
                 $item->get_products = static::lazy_load(function () use($item) {
                     $products = Model_Product_To_Groups::find(function ($query) use($item) {
                         return $query->where('group_id', $item->id);
                     }, 'product_id');
                     if (!empty($products)) {
                         $products = '(' . implode(',', array_keys($products)) . ')';
                         return Model_Product::find(function ($query) use($products, $item) {
                             $query->where('id', 'IN', \DB::expr($products));
                             $query->order_by('sort', 'asc');
                             return $query;
                         }, 'id');
                     }
                     return array();
                 }, $item->id, 'products');
                 // Get content children
                 $item->get_children = static::lazy_load(function () use($item) {
                     return Model_Group::find(array('where' => array('parent_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'children');
                 // Get group images
                 $item->get_images = static::lazy_load(function () use($item) {
                     return Model_Group_Image::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'images');
                 // Get group discount options
                 // Use one more item property (user_group_id)
                 // It can be set using methods (set_user_group_id and get_user_group_id)
                 $item->get_discount_options = static::lazy_load(function () use($item) {
                     $options = Model_Group_Options::find(array('where' => array('user_group_id' => $item->get_user_group_id(), 'product_group_id' => $item->id)));
                     return isset($options[0]) ? $options[0] : array();
                 }, $item->id, 'discount_options', 'object');
                 // Get group discount options
                 // Use one more item property (user_group_id)
                 // It can be set using methods (set_user_group_id and get_user_group_id)
                 $item->get_discounts = static::lazy_load(function () use($item) {
                     return Model_Group_Discounts::find(array('where' => array('user_group_id' => $item->get_user_group_id(), 'product_group_id' => $item->id), 'order_by' => array('qty' => 'asc')), 'qty');
                 }, $item->id, 'discounts');
                 // DO NOT CHANGE THIS TWO FUNCTIONS AS THEY ARE NEEDED
                 $item->set_user_group_id = function ($user_group_id = NULL) {
                     \Product\Model_Group::$user_group_id = $user_group_id;
                 };
                 $item->get_user_group_id = function () {
                     return \Product\Model_Group::$user_group_id;
                 };
             }
         }
     }
     // return the result
     return $result;
 }
Пример #15
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 product categories
                 $item->get_categories = static::lazy_load(function () use($item) {
                     $categories = Model_Product_To_Categories::find(function ($query) use($item) {
                         return $query->where('product_id', $item->id);
                     }, 'category_id');
                     if (!empty($categories)) {
                         $categories = '(' . implode(',', array_keys($categories)) . ')';
                         return Model_Category::find(function ($query) use($categories) {
                             return $query->where('id', 'IN', \DB::expr($categories));
                         }, 'id');
                     }
                     return array();
                 }, $item->id, 'categories');
                 // Get product infotabs
                 $item->get_infotabs = static::lazy_load(function () use($item) {
                     return Model_Product_To_Infotabs::find(function ($query) use($item) {
                         $query->order_by('sort', 'asc');
                         return $query->where('product_id', $item->id);
                     });
                 }, $item->id, 'infotabs');
                 // Get product groups
                 $item->get_groups = static::lazy_load(function () use($item) {
                     $groups = Model_Product_To_Groups::find(function ($query) use($item) {
                         return $query->where('product_id', $item->id);
                     }, 'group_id');
                     if (!empty($groups)) {
                         $groups = '(' . implode(',', array_keys($groups)) . ')';
                         return Model_Group::find(function ($query) use($groups, $item) {
                             $query->where('id', 'IN', \DB::expr($groups));
                             $query->order_by('sort', 'asc');
                             return $query;
                         }, 'id');
                     }
                     return array();
                 }, $item->id, 'groups');
                 // Get product groups
                 $item->get_pricing_group = static::lazy_load(function () use($item) {
                     $groups = Model_Product_To_Groups::find(function ($query) use($item) {
                         return $query->where('product_id', $item->id);
                     }, 'group_id');
                     if (!empty($groups)) {
                         $groups = '(' . implode(',', array_keys($groups)) . ')';
                         $groups = Model_Group::find(function ($query) use($groups, $item) {
                             $query->where('type', 'pricing');
                             $query->where('id', 'IN', \DB::expr($groups));
                             $query->order_by('sort', 'asc');
                             return $query;
                         });
                         return !empty($groups) ? $groups[0] : false;
                     }
                     return false;
                 }, $item->id, 'pricing_group', 'object');
                 // Get related products
                 $item->get_related_products = static::lazy_load(function () use($item) {
                     $related = Model_Product_To_Related::find(function ($query) use($item) {
                         return $query->where('product_id', $item->id);
                     }, 'related_id');
                     if (!empty($related)) {
                         $related = '(' . implode(',', array_keys($related)) . ')';
                         return Model_Product::find(function ($query) use($related, $item) {
                             $query->where('id', 'IN', \DB::expr($related));
                             $query->where('id', '<>', $item->id);
                             $query->order_by('sort', 'asc');
                             return $query;
                         }, 'id');
                     }
                     return array();
                 }, $item->id, 'related_products');
                 // Get upsell products
                 $item->get_upsell_products = static::lazy_load(function () use($item) {
                     $upsell = Model_Product_To_Upsell::find(function ($query) use($item) {
                         return $query->where('product_id', $item->id);
                     }, 'upsell_id');
                     if (!empty($upsell)) {
                         $upsell = '(' . implode(',', array_keys($upsell)) . ')';
                         return Model_Product::find(function ($query) use($upsell, $item) {
                             $query->select(Model_Product_To_Upsell::get_protected('_table_name') . '.discount', Model_Product::get_protected('_table_name') . '.*');
                             $query->join(Model_Product_To_Upsell::get_protected('_table_name'));
                             $query->on(Model_Product_To_Upsell::get_protected('_table_name') . '.upsell_id', '=', Model_Product::get_protected('_table_name') . '.id');
                             $query->where(Model_Product::get_protected('_table_name') . '.id', 'IN', \DB::expr($upsell));
                             $query->where(Model_Product::get_protected('_table_name') . '.id', '<>', $item->id);
                             $query->order_by(Model_Product::get_protected('_table_name') . '.sort', 'asc');
                             return $query;
                         }, 'id');
                     }
                     return array();
                 }, $item->id, 'upsell_products');
                 // Get content images
                 $item->get_images = static::lazy_load(function () use($item) {
                     return Model_Product_Image::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'images');
                 // Get content files
                 $item->get_files = static::lazy_load(function () use($item) {
                     return Model_Product_File::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'files');
                 // Get content videos
                 $item->get_videos = static::lazy_load(function () use($item) {
                     return Model_Product_Video::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'videos');
                 // Get content children
                 $item->get_seo = static::lazy_load(function () use($item) {
                     return Model_Product_Seo::find_one_by_content_id($item->id);
                 }, $item->id, 'seo', 'object');
                 // Get attributes
                 $item->get_attributes = static::lazy_load(function () use($item) {
                     return Model_Attribute::find(array('where' => array('product_id' => $item->id)));
                 }, $item->id, 'attributes');
                 // Get default attribute
                 $item->get_default_attributes = static::lazy_load(function () use($item) {
                     return Model_Attribute::find(array('where' => array('product_id' => $item->id, 'default' => 1, 'active' => 1)));
                 }, $item->id, 'default_attributes');
                 // Get all active prices
                 $item->get_all_prices = static::lazy_load(function () use($item) {
                     $product_attributes = Model_Attribute::find(function ($query) use($item) {
                         $query->join(Model_Attribute_Price::get_protected('_table_name'));
                         $query->on(Model_Attribute_Price::get_protected('_table_name') . '.product_attribute_id', '=', Model_Attribute::get_protected('_table_name') . '.id');
                         $query->where('product_id', $item->id);
                         $query->and_where('attributes', '!=', '');
                         $query->and_where('active', 1);
                         return $query;
                     }, 'id');
                     return $product_attributes;
                 }, $item->id, 'unit_price');
                 // Get prices for product
                 $item->get_prices = static::lazy_load(function () use($item) {
                     $product_attributes = Model_Attribute::find(function ($query) use($item) {
                         $query->join(Model_Attribute_Price::get_protected('_table_name'));
                         $query->on(Model_Attribute_Price::get_protected('_table_name') . '.product_attribute_id', '=', Model_Attribute::get_protected('_table_name') . '.id');
                         $query->where('product_id', $item->id);
                         return $query;
                     }, 'id');
                     return $product_attributes;
                 }, $item->id, 'unit_price');
                 // Get unit price
                 $item->get_unit_price = static::lazy_load(function () use($item) {
                     $product_attributes = Model_Attribute::find(function ($query) use($item) {
                         $query->join(Model_Attribute_Price::get_protected('_table_name'));
                         $query->on(Model_Attribute_Price::get_protected('_table_name') . '.product_attribute_id', '=', Model_Attribute::get_protected('_table_name') . '.id');
                         $query->where('product_id', $item->id);
                         $query->and_where('type', 'unit_price');
                         $query->and_where('attributes', '!=', '');
                         $query->and_where('active', 1);
                         $query->limit(1);
                         return $query;
                     }, 'id');
                     return $product_attributes;
                 }, $item->id, 'unit_price');
                 // Get sale price
                 $item->get_sale_price = static::lazy_load(function () use($item) {
                     $product_attributes = Model_Attribute::find(function ($query) use($item) {
                         $query->join(Model_Attribute_Price::get_protected('_table_name'));
                         $query->on(Model_Attribute_Price::get_protected('_table_name') . '.product_attribute_id', '=', Model_Attribute::get_protected('_table_name') . '.id');
                         $query->where('product_id', $item->id);
                         $query->and_where('type', 'sale_price');
                         $query->and_where('attributes', '!=', '');
                         $query->and_where('active', 1);
                         $query->limit(1);
                         return $query;
                     }, 'id');
                     return $product_attributes;
                 }, $item->id, 'sale_price');
                 // Get default price (RRP or Sale price)
                 $item->get_default_price = static::lazy_load(function () use($item) {
                     $out = array(0);
                     $product_attributes = Model_Attribute::find(function ($query) use($item) {
                         $query->join(Model_Attribute_Price::get_protected('_table_name'));
                         $query->on(Model_Attribute_Price::get_protected('_table_name') . '.product_attribute_id', '=', Model_Attribute::get_protected('_table_name') . '.id');
                         $query->where('product_id', $item->id);
                         $query->and_where('type', 'sale_price');
                         $query->and_where('attributes', '!=', '');
                         $query->and_where('active', 1);
                         $query->and_where('default', 1);
                         $query->limit(1);
                         return $query;
                     }, 'id');
                     if ($product_attributes) {
                         $obj = reset($product_attributes);
                         if ($obj->price > 0) {
                             $out[0] = $obj->price;
                             $out[1] = 'sale_price';
                         } else {
                             $out[0] = $obj->retail_price;
                             $out[1] = 'retail_price';
                         }
                     }
                     return $out;
                 }, $item->id, 'default_price');
                 // Get active attribute group
                 $item->get_active_attribute_group = static::lazy_load(function () use($item) {
                     if ($attribute = Model_Attribute::find_one_by_product_id($item->id)) {
                         return $attribute->attribute_group;
                     }
                     return false;
                 }, $item->id, 'active_attribute_group');
                 // Get product data
                 $item->get_data = static::lazy_load(function () use($item) {
                     return \Product\Model_Product::product_data($item);
                 }, $item->id, 'data');
             }
         }
     }
     // return the result
     return $result;
 }
Пример #16
0
 public function action_edit($id = null)
 {
     if (!Sentry::user()->has_access('groups_edit')) {
         self::no_access();
     }
     $groups = Model_Group::access(intval($id));
     $group['permissions'] = json_decode($groups[0]['permissions'], true);
     $group['groupName'] = $groups[0]['name'];
     if (Input::method() == 'POST') {
         if (!Input::post('groupName')) {
             Session::set_flash('error', 'Please choose a name for the group');
         } else {
             $post = Input::post();
             $groupName = $post['groupName'];
             unset($post['groupName']);
             // JSON_NUMERIC_CHECK to keep the int
             $permissions = json_encode($post, JSON_NUMERIC_CHECK);
             $updated = Model_Group::editGroup(intval($id), $groupName, $permissions);
             if ($updated) {
                 Session::set_flash('success', 'The group ' . $groupName . ' has been successfully edited');
                 Response::redirect('groups');
             }
         }
     }
     $var = self::access();
     // all the access
     View::set_global('var', $var);
     // all the needed informations about the current group
     View::set_global('group', $group);
     $this->template->h2 = 'Edit Group';
     $this->template->title = 'Groups &raquo; Edit';
     $this->template->js .= Asset::js(array('mylibs/jquery.validate.js', 'script.js'));
     $this->template->content = View::forge('groups/edit');
 }
Пример #17
0
 public function usergroups_select_array()
 {
     $groups = array();
     foreach (Model_Group::find('all') as $group) {
         $groups[$group->id] = $group->name;
     }
     return $groups;
 }
Пример #18
0
 public function getAclResources($userRowset)
 {
     $role = Model_Group::GUEST_ROLE;
     if (isset($userRowset->role) && !empty($userRowset->role)) {
         $role = $userRowset->role;
     }
     $mdlGroup = new Model_Group();
     return $mdlGroup->getAclResources($role);
 }
Пример #19
0
 public static function _init()
 {
     parent::_init();
     $objects = \Model_Group::find('all', array('order_by' => 'level'));
     static::$groups = Petro::obj_to_keyval($objects, 'level', 'name');
 }
Пример #20
0
 public function action_delete($id = false)
 {
     if (is_numeric($id)) {
         // Get news item to edit
         if ($item = Model_Group::find_one_by_id($id)) {
             // Delete item
             try {
                 // Delete all relations of this group with products
                 $groups = Model_Product_To_Groups::find_by_group_id($item->id);
                 if (!empty($groups)) {
                     foreach ($groups as $group) {
                         $group->delete();
                     }
                 }
                 $groups = Model_Group_Options::find_by_product_group_id($item->id);
                 if (!empty($groups)) {
                     foreach ($groups as $group) {
                         $group->delete();
                     }
                 }
                 if (!empty($item->images)) {
                     foreach ($item->images as $image) {
                         $this->delete_image($image->image);
                         $image->delete();
                     }
                 }
                 // Delete group
                 $item->delete();
                 \Messages::success('Group successfully deleted.');
             } catch (\Database_Exception $e) {
                 // show validation errors
                 \Messages::error('<strong>There was an error while trying to delete group</strong>');
                 // Uncomment lines below to show database errors
                 //$errors = $e->getMessage();
                 //\Messages::error($errors);
             }
         }
     }
     \Response::redirect(\Input::referrer());
 }
Пример #21
0
 /**
  * Defined by Zend_Validate_Interface
  *
  * Returns true if and only if $value does exist already as group name
  *
  * @param  string $value
  * @return boolean
  */
 public function isValid($value)
 {
     $value = (string) $value;
     $this->_setValue($value);
     $mdlGroup = new Model_Group();
     if ($mdlGroup->groupExists($value, $this->getExclude())) {
         return true;
     }
     $this->_error(self::NOT_EXISTS);
     return false;
 }
Пример #22
0
 /**
  * Delete action
  *
  * Delete a group
  *
  * @return void
  */
 public function deleteAction()
 {
     $groupName = $this->_request->getParam('groupname');
     $mdlGroup = new Model_Group();
     // TODO: display error message or warning
     if (Model_Group::SUPERUSER_ROLE != $groupName && Model_Group::GUEST_ROLE != $groupName) {
         $mdlGroup->delete("name = '{$groupName}'");
     }
     $url = 'admin/site';
     $this->_redirect($url);
 }
Пример #23
0
        echo Html::anchor('groups/view/' . $group['id'], $group['name']);
        ?>
</td>
			<?php 
    } else {
        ?>
			<td><?php 
        echo $group['name'];
        ?>
</td>
			<?php 
    }
    ?>
			
			<?php 
    $right = Model_Group::access($group['id']);
    ?>

			<td><?php 
    echo count(Sentry::group($group['id'])->users());
    ?>
</td>

			<td><?php 
    echo round(count(isset(json_decode($right[0]['permissions'])->superuser) ? new SplFixedArray($total) : (array) json_decode($right[0]['permissions'])) * 100 / $total, 0, PHP_ROUND_HALF_EVEN);
    ?>
/100</td>
			<?php 
    if (Sentry::user()->has_access('groups_edit') || Sentry::user()->has_access('groups_delete')) {
        ?>
			<td><?php