public function nr($id = null) { $is_loged = LoginVal::isLogged(); $http = new Http(); $this->product_m = new \models\Product($id[0]); $name = $this->product_m->getName(); if (empty($name)) { Location::To(URL . 'error'); } $available = $this->product_m->getQuantity(); $promotions = new Promotions($id[0]); $pro = $promotions->getPromotion(); if (!empty($pro)) { $old_price = $this->product_m->getOldPrice($pro->getPercent()); $discount = $pro->getPercent() * 100; } $additionals = $this->product_m->getAdditionals(); $a_images = $this->product_m->getAdditionalImages(); $comments_m = new Comments($id[0]); $pagination = new Pagination(2, $comments_m->getNumberOfComments()); $avg_rating = $comments_m->getAverageRating(); $comments = $comments_m->getComments(2, $pagination->page($id[1])); $next = $pagination->next(); $prev = $pagination->prev(); $num_pages = $pagination->getPages(); $selected = $pagination->getSelected(); $comment = $http->post('comment'); if (!empty($comment) && $is_loged && $http->isActive('send') && !empty($this->product_m)) { $comment = new Comment(); $comment->setComment($http->post('comment')); $comment->setDate(); $comment->setProductId($this->product_m->getId()); $comment->setUserId(Register::get('id')); $comment->setRate($http->post('star')); $comment->writeData(); Location::To(URL . 'product/nr/' . $id[0]); } $comment_tab = array(); if (!empty($comments)) { foreach ($comments as $key => $comment) { if (!empty($comment)) { $comment_tab[$key]['comment'] = $comment->getComment(); $comment_tab[$key]['date'] = $comment->getDate(); $comment_tab[$key]['rate'] = $comment->getRate(); $user = new \models\Users($comment->getUserId()); $login = $user->getLogin(); $comment_tab[$key]['login'] = empty($login) ? 'anonimowy' : $login; } } } $this->render('product', array('categories' => $this->categories, 'd_product' => $this->d_product, 'category' => $this->product_m->getCategory(), 'name' => $this->product_m->getName(), 'description' => $this->product_m->getDescription(), 'image' => $this->product_m->getImage(), 'quantity' => $this->product_m->getQuantity(), 'price' => $this->product_m->getPrice(), 'additionals' => $additionals, 'images' => $a_images, 'comments' => $comment_tab, 'product_nr' => $id[0], 'next' => $next, 'prev' => $prev, 'num_pages' => $num_pages, 'selected' => $selected, 'is_loged' => $is_loged, 'avg_rating' => $avg_rating, 'discount' => $discount, 'old_price' => $old_price, 'available' => $available)); }
public function createComments() { if (!$this->meta->exists($this->table)) { $this->fw->error(404); return; } \models\Comments::create($this->table); \Cache::instance()->reset(); $this->fw->reroute('/account/settings/comments'); }
/** * Устанвливает пользовательское меню */ protected function setAccountMenu() { $menu = []; $rules = ACLdata::getInstance()->getRules($this->user_group_id); // Модерирование комментариев if (in_array('comment', $rules[ACLdata::RELATION_NO][ACLdata::ACTION_MODERATION])) { $has_comments = \models\meta\Meta::getInstance()->getListBySetting('is_commentable', true); if (!empty($has_comments)) { array_push($menu, ['type' => 'header', 'title' => $this->fw->get('i18n.user.menu.moderation')]); $count_comments = \models\Comments::getCountWaiting(); array_push($menu, ['object' => 'comments', 'action' => 'moderation', 'icon' => 'fui-checkbox-checked', 'title' => $this->fw->get('i18n.user.menu.comments.title'), 'count' => array_sum($count_comments)]); array_push($menu, ['type' => 'divider']); } } $read_rules = array_merge($rules[ACLdata::RELATION_NO][ACLdata::ACTION_READ], $rules[ACLdata::RELATION_OWN][ACLdata::ACTION_READ], $rules[ACLdata::RELATION_REF][ACLdata::ACTION_READ], $rules[ACLdata::RELATION_PARENT][ACLdata::ACTION_READ]); $read_admin = $rules[ACLdata::RELATION_NO][ACLdata::ACTION_READ]; if (in_array('_user', $read_rules)) { array_push($menu, array('object' => 'user', 'href' => '/account/user', 'icon' => 'fui-user', 'title' => $this->fw->get('i18n.user.menu.users.title'))); } // TODO: проверить // if ($this->fw->exists('importer')) { // $this->fw->config($this->fw->get('ROOT') . '/../' . APP_FOLDER . '/cfg/importer.ini'); // $menu = array_merge($menu, Importer::getMenu()); // } $content = array(); $tmp = \models\meta\Meta::getInstance()->getList(); foreach ($tmp as $v) { $table = $v->get('table'); if ($table != '_user_profile' && in_array($table, $read_rules)) { $model = \models\ContentList::getInstance($table); $content[$v->get('title')] = array('object' => 'content', 'params' => 'table=' . $table, 'icon' => 'fui-list', 'title' => !is_null($v->get('title_pl')) ? $v->get('title_pl') : $v->get('title'), 'count_own' => $model->getCount(['user_id=?', $this->user_id]), 'count' => $read_admin ? $model->getCount() : ''); } } if (!empty($content)) { ksort($content); array_unshift($content, ['type' => 'header', 'title' => $this->fw->get('i18n.user.menu.content.list')]); $menu = array_merge($menu, $content); } if (in_array('_group', $read_rules) || in_array('_acl', $read_rules)) { $menu = array_merge($menu, array(['type' => 'divider'], ['type' => 'header', 'title' => $this->fw->get('i18n.user.menu.rights.title')])); if (in_array('_group', $read_rules)) { $menu = array_merge($menu, array(array('object' => 'group', 'icon' => 'fui-list-thumbnailed', 'title' => $this->fw->get('i18n.user.menu.groups.title')))); } if (in_array('_acl', $read_rules)) { $menu = array_merge($menu, array(array('object' => 'acl', 'icon' => 'fui-list-thumbnailed', 'title' => $this->fw->get('i18n.user.menu.acl.title')))); } } if (in_array('_service', $read_rules)) { $menu = array_merge($menu, array(['type' => 'divider'], ['type' => 'header', 'title' => $this->fw->get('i18n.user.menu.service.title')], array('object' => 'static_blocks', 'icon' => 'fui-list-thumbnailed', 'title' => $this->fw->get('i18n.user.menu.static.title')), array('object' => 'static_places', 'icon' => 'fui-list-small-thumbnails', 'title' => $this->fw->get('i18n.user.menu.static.places.title')), array('object' => 'service', 'action' => 'resetcache', 'icon' => 'glyphicon glyphicon-refresh', 'title' => $this->fw->get('i18n.cache.reset.title')), array('object' => 'service', 'action' => 'phpinfo', 'icon' => 'fui-info', 'title' => 'PHPINFO'), array('object' => 'meta', 'icon' => 'fui-gear', 'title' => $this->fw->get('i18n.user.menu.contentmeta.title')), array('object' => 'comments', 'icon' => 'fui-gear', 'title' => $this->fw->get('i18n.user.menu.comments.title')))); } //\helpers\Debug::prePrintR($this->fw->get('PARAMS')); for ($i = 0; $i < count($menu); $i++) { if (isset($menu[$i]['href']) && $menu[$i]['href'] == $this->fw->get('PARAMS.0')) { $menu[$i]['class'] = 'active'; } } $this->fw->set('MENUS.account', $menu); $this->fw->set('html.account_js', true); }
public function deleteProduct() { $http = new Http(); $id = $http->post("id"); if ($id) { $product = new Product($id); $product->delete(); $product_additional_images = new ProductAdditionalImages($id, true); $product_additional_images->deleteAllAdditionalImages(); $product_additional = new ProductAdditional($id, true); $product_additional->deleteAllFields(); $product_promotion = new Promotion(); $product_promotion->deletePromotionByProductId($id); $product_comments = new Comments($id); $product_comments->deleteAllComents(); } }
/** * @return string approved comments count for object */ public function getCommentsCount() { $pk = $this->getObjectPkAttribute(); $comments = \Models\Comments::query()->where("class_name = :class_name:")->andWhere("object_pk = :object_pk:")->bind(array("class_name" => $this->getClassName(), "object_pk" => $this->getOwner()->{$pk}))->execute(); return $comments->count(); }