private function setCategoryTitleSmall($categoryID = 0)
	{
		$category = Categories::findFirst($categoryID);		
		$this->view->h1_small = $category->title;		
		
		$this->view->categoryID = $categoryID;
	}
Exemple #2
0
 public static function getCatPath($cid)
 {
     $catPath = '';
     $category = Categories::findFirst(array('conditions' => 'id=?1', 'bind' => array(1 => $cid)));
     if ($category->level >= 2) {
         $cats = Categories::find(array('conditions' => 'lpoint<=?1 and rpoint>=?2 and level>=?3 and level<=?4', 'bind' => array(1 => $category->lpoint, 2 => $category->rpoint, 3 => 2, 4 => 3), 'order' => 'level'))->toArray();
         foreach ($cats as $cat) {
             $catPath .= $catPath ? '/' . $cat['title_en'] : $cat['title_en'];
         }
     }
     return $catPath;
 }
 public static function update($id, $data)
 {
     $response = new Response();
     try {
         $data = json_decode($data, true);
         /** @var Categories $categories */
         $category = Categories::findFirst($id);
         $category->setAttributes($data);
         $response->data = $category->update();
     } catch (Exception $e) {
         $response->setException($e);
     } finally {
         return $response->toArray();
     }
 }
	protected function saveAction($id = 0)
	{
		if ($id)
		{
			$action = 'edit';
			$category = Categories::findFirst($id);
			
	        if (!$category) 
	        {
	            $this->flash->error("Element not found");
	            return $this->forward("categories/index");
	        }
		}
		else 
		{
			$action = 'new';
			$category = new Categories;
		}
		
		$form = new CategoriesForm;
		
        $data = $this->request->getPost();
		
        if (!$form->isValid($data, $category)) 
        {
            foreach ($form->getMessages() as $message) 
            {
                $this->flash->error($message);
            }
            return $this->forward('categories/' . $action);
        }

        if ($category->save() == false) 
        {
            foreach ($category->getMessages() as $message) 
            {
                $this->flash->error($message);
            }
            return $this->forward('categories/' . $action);
        }

        $form->clear();

        $this->flash->success("Элемент успешно сохранен");
        return $this->forward("categories/index");		
	}
 public function taggedAction($tag)
 {
     $tag = $this->filter->sanitize($tag, "alphanum");
     Phalcon_Tag::setTitle('Tagged ' . $tag);
     $category = Categories::findFirst("name='{$tag}'");
     if ($category == false) {
         return $this->_forward('index/index');
     }
     $news = array();
     $newsCategories = NewsCategories::find(array("categories_id='" . $category->id . "'"));
     foreach ($newsCategories as $newCategory) {
         $news[] = $newCategory->getNews();
     }
     $this->view->setVar("activeYear", 0);
     $this->view->setVar("tag", $tag);
     $this->view->setVar("news", $news);
     $this->view->setVar("years", News::count(array('group' => 'year')));
 }
	public function fillFullTitle()
	{
		$categories = array();
		
		foreach(Categories::find() as $category)
		{
			$categories[$category->parentID][$category->id] = $category->title;
		}
		
		$helpers = new Helpers;
		
		$titles = $helpers->titleRecursive($categories);

		foreach ($titles as $id => $title)
		{
			$category = Categories::findFirst($id);
			$category->titleFull = $title;
			$category->save();		
		}
	}
Exemple #7
0
 public function taggedAction($tag)
 {
     $tag = $this->filter->sanitize($tag, "alphanum");
     $exists = $this->view->getCache()->exists($tag);
     if (!$exists) {
         Phalcon\Tag::setTitle('Tagged ' . $tag);
         $category = Categories::findFirst("name='{$tag}'");
         if ($category == false) {
             return $this->dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
         }
         $news = array();
         $newsCategories = NewsCategories::find(array("categories_id='" . $category->id . "'"));
         foreach ($newsCategories as $newCategory) {
             $news[] = $newCategory->getNews();
         }
         $this->view->setVar("activeYear", 0);
         $this->view->setVar("tag", $tag);
         $this->view->setVar("news", $news);
         $this->view->setVar("years", News::count(array('group' => 'year')));
     }
     $this->view->cache(array("lifetime" => 86400, "key" => $tag));
 }
Exemple #8
0
 public static function create($data)
 {
     $response = new Response();
     try {
         $data = json_decode($data, true);
         $category = Categories::findFirst($data->categoryId);
         if ($category !== FALSE) {
             /** @var Products $products */
             $product = new Products();
             $product->setAttributes($data);
             $response->data = $product->create();
             $response->status = $response::STATUS_CREATED;
         } else {
             $response->status = $response::STATUS_BAD_REQUEST;
             $response->addError('CATEGORIES_NOT_FOUND');
         }
     } catch (Exception $e) {
         $response->setException($e);
     } finally {
         return $response->toArray();
     }
 }
 public function setplaceAction()
 {
     $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
     if (is_numeric($this->request->getPost('cat_id')) && $this->request->hasPost('cat_id') && $this->request->isAjax()) {
         $cat_id = $this->request->getPost('cat_id');
         foreach (FieldType::find() as $fl) {
             if ($fl->id == 4) {
                 $field[$fl->id] = array($fl->name, $fl->dtype, $fl->pref);
             }
         }
         if (!$this->request->hasPost('sub')) {
             foreach (Categories::find(array("id ={$cat_id} or id_sub ={$cat_id}")) as $categ) {
                 foreach ($categ->fieldtype as $fil) {
                     if (strpos($fil->dtype, "a:") !== false) {
                         $field[$fil->id] = array($fil->name, unserialize($fil->dtype), $fil->pref);
                     } else {
                         $field[$fil->id] = array($fil->name, $fil->dtype, $fil->pref);
                     }
                 }
             }
         } else {
             $ct = Categories::findFirst($cat_id)->id_sub;
             foreach (Categories::find(array("id ={$ct} or id ={$cat_id}")) as $categ) {
                 foreach ($categ->fieldtype as $fil) {
                     if (strpos($fil->dtype, "a:") !== false) {
                         $field[$fil->id] = array($fil->name, unserialize($fil->dtype), $fil->pref);
                     } else {
                         $field[$fil->id] = array($fil->name, $fil->dtype, $fil->pref);
                     }
                 }
             }
         }
         $this->view->setVars(array('field' => $field = isset($field) ? $field : false));
     } else {
         $this->view->setVars(array('field' => $field = isset($field) ? $field : false));
     }
 }
 public function deleteAction($id)
 {
     $categories = Categories::findFirst(array('id = :id:', 'bind' => array('id' => $id)));
     if (!$categories) {
         $this->flash->error("The category was not found");
         return $this->dispatcher->forward(array("controller" => "categories", "action" => "index"));
     }
     if (!$categories->delete()) {
         foreach ($categories->getMessages() as $message) {
             $this->flash->error((string) $message);
         }
         return $this->dispatcher->forward(array("controller" => "categories", "action" => "search"));
     } else {
         $this->flash->success("The category was deleted");
         return $this->dispatcher->forward(array("controller" => "categories", "action" => "index"));
     }
 }
 public function redofferAction()
 {
     $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
     if ($this->request->hasPost('offer_id')) {
         foreach (FieldType::find() as $field) {
             $fil[$field->id] = $field->name;
         }
         $offer = Offers::findFirst($this->request->getPost('offer_id'));
         foreach ($offer->dannoffers as $dan) {
             $dan_fil[$dan->fieldtype->id] = $dan->dann;
         }
         $cat = $offer->categories;
         $cat_id = $cat->id;
         foreach (Categories::find(array("id_sub =0")) as $categ) {
             $category[$categ->id] = $categ->name;
         }
         // Получение родительской категории
         if (count(Categories::find(array("id_sub = {$cat->id}"))) > 0) {
             foreach (Categories::find(array("id_sub = {$cat->id}")) as $categ) {
                 $sub_cat[$categ->id] = $categ->name;
             }
         } else {
             foreach (Categories::find(array("id = {$cat->id_sub}")) as $categ) {
                 $par_cat = $categ->id;
                 foreach (Categories::find(array("id_sub = {$categ->id}")) as $cate) {
                     $sub_cat[$cate->id] = $cate->name;
                 }
             }
         }
         if (count(Categories::find(array("id = {$cat->id_sub}"))) > 0) {
             foreach (Categories::findFirst(array("id = {$cat->id_sub}"))->fieldtype as $cat_field) {
                 $cat_fd[$cat_field->id] = array($cat_field->name, $cat_field->pref, $cat_field->dtype);
             }
         }
         foreach ($cat->fieldtype as $cat_field) {
             $cat_f[$cat_field->id] = array($cat_field->name, $cat_field->pref, $cat_field->dtype);
         }
         //  $this->elements->var_print($dan_fil);
         if (!isset($sub_cat)) {
             $par_cat = $cat_id;
         }
         $this->view->setVars(array('field' => $fil, 'cat_field' => $cat_f = isset($cat_f) ? $cat_f : false, 'cat_fieldf' => $cat_fd = isset($cat_fd) ? $cat_fd : false, 'offer_name' => $offer_name = isset($offer->name) ? $offer->name : false, 'offer_text' => $off = isset($offer->text) ? $offer->text : false, 'offer_id' => $off = isset($offer->id) ? $offer->id : false, 'dan_fil' => $dan_fil = isset($dan_fil) ? $dan_fil : false, 'par_cat' => $par_cat = isset($par_cat) ? $par_cat : false, 'cat_id' => $cat_id = isset($cat_id) ? $cat_id : false, 'cat' => $category = isset($category) ? $category : false, 'sub_cat' => $sub_cat = isset($sub_cat) ? $sub_cat : false));
     }
 }
 public function offerAction()
 {
     $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
     if (isset($_POST['offer'])) {
         $offer_id = $this->request->getPost('offer');
         $offer = Offers::findFirst($offer_id);
         $date = new DateTime($offer->creation_date);
         $date = $date->format('Y-m-d H:i');
         if (isset($offer->image)) {
             $image = unserialize($offer->image);
         } else {
             $image = '';
         }
         foreach ($offer->dannoffers as $dann) {
             if ($dann->field_type_id == 14) {
                 $operator = $dann->dann;
             } elseif ($dann->field_type_id == 7) {
                 $gsm = $dann->dann;
             } elseif ($dann->field_type_id == 6) {
                 $dost = $dann->dann;
             } elseif ($dann->field_type_id == 15) {
                 $rad_dost = $dann->dann . " " . $dann->fieldtype->pref;
             } elseif ($dann->field_type_id == 16) {
                 $stat = $dann->dann;
             } elseif ($dann->field_type_id == 5) {
                 $price = $dann->dann;
             } elseif ($dann->field_type_id == 17) {
                 $spec = $dann->dann;
             }
             foreach ($offer->categories->fieldtype as $field) {
                 if ($field->id == $dann->field_type_id) {
                     $cat_dann[$field->name] = $dann->dann . " " . $field->pref;
                 }
             }
             if (count(Categories::find(array("id = {$offer->categories->id_sub}"))) > 0) {
                 foreach (Categories::findFirst(array("id = {$offer->categories->id_sub}"))->fieldtype as $fiel) {
                     if ($fiel->id == $dann->field_type_id) {
                         $cat_dann[$fiel->name] = $dann->dann . " " . $fiel->pref;
                     }
                 }
             }
         }
         foreach ($offer->comments as $comment) {
             $comm[$comment->id] = array('reciever' => $comment->user->first_name, 'text' => $comment->text, 'date' => $comment->creation_date);
         }
         $this->view->setVars(array('name' => $nm = isset($offer->user->first_name) ? $offer->user->first_name : false, 'user_id' => $id_u = isset($offer->user->id) ? $offer->user->id : false, 'offer_id' => $id = isset($offer->id) ? $offer->id : false, 'offer_name' => $of_name = isset($offer->name) ? $offer->name : false, 'offer_date' => $dat = isset($date) ? $date : false, 'offer_text' => $text = isset($offer->text) ? $offer->text : false, 'offer_image' => $image, 'oper' => $oper = isset($operator) ? $operator : false, 'gsm' => $gsm = isset($gsm) ? $gsm : false, 'dost' => $dost = isset($dost) ? $dost : false, 'radius_d' => $rad_dost = isset($rad_dost) ? $rad_dost : false, 'status' => $stat = isset($stat) ? $stat : false, 'price' => $price = isset($price) ? $price : false, 'cat_dann' => $cat_dann = isset($cat_dann) ? $cat_dann : false, 'spec' => $spec = isset($spec) ? $spec : false, 'comments' => $comm = isset($comm) ? $comm : false));
     }
 }
 public function redorderAction()
 {
     $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
     if ($this->request->hasPost('order') && $this->request->isAjax()) {
         $prop = Proposal::findFirst($this->request->getPost('order'));
         if (count($prop->dannproposal) > 0) {
             foreach ($prop->dannproposal as $dann) {
                 $dan[$dann->fieldtype->id] = $dann->dann;
             }
         }
         $categories = $prop->categories;
         $cat_id = $prop->categories->id;
         foreach (Categories::find(array("id_sub = 0")) as $cat) {
             $cat_dann[$cat->id] = $cat->name;
         }
         if ($prop->categories->id_sub == 0) {
             $par_cat = $cat_id;
             if (count(Categories::find(array("id_sub = {$cat_id}"))) > 0) {
                 foreach (Categories::find(array("id_sub = {$cat_id}")) as $categ) {
                     $sub_cat[$categ->id] = $categ->name;
                 }
             }
         } else {
             if (count(Categories::find(array("id = {$categories->id_sub}"))) > 0) {
                 $categ = Categories::findFirst(array("id = {$categories->id_sub}"));
                 foreach (Categories::find(array("id_sub = {$categ->id}")) as $cate) {
                     $sub_cat[$cate->id] = $cate->name;
                 }
                 $par_cat = $categ->id;
                 //   $this->elements->var_print($sub_cat);
             }
         }
         $this->view->setVars(array('order_id' => $id = isset($prop->id) ? $prop->id : false, 'par_cat' => $par_cat = isset($par_cat) ? $par_cat : false, 'cat_id' => $cat_id = isset($cat_id) ? $cat_id : false, 'cat' => $cat_dann = isset($cat_dann) ? $cat_dann : false, 'sub_cat' => $sub_cat = isset($sub_cat) ? $sub_cat : false, 'price_hour' => $price = isset($prop->price_hour) ? $prop->price_hour : false, 'date_to' => $date = isset($prop->date_to) ? $prop->date_to : false, 'date_from' => $date = isset($prop->date_from) ? $prop->date_from : false, 'text' => $text = isset($prop->text) ? $prop->text : false, 'dann' => $dan = isset($dan) ? $dan : false));
     }
 }