public function searchAction()
 {
     $numberPage = 1;
     if ($this->request->isPost()) {
         $query = Criteria::fromInput($this->di, "Categories", $_POST);
         $this->session->conditions = $query->getConditions();
     } else {
         $numberPage = $this->request->getQuery("page", "int");
         if ($numberPage <= 0) {
             $numberPage = 1;
         }
     }
     $parameters = array();
     if ($this->session->conditions) {
         $parameters["conditions"] = $this->session->conditions;
     }
     $parameters["order"] = "id";
     $categories = Categories::find($parameters);
     if (count($categories) == 0) {
         $this->flash->notice("The search did not find any categories");
         return $this->dispatcher->forward(array("controller" => "categories", "action" => "index"));
     }
     $paginator = new \Phalcon\Paginator\Adapter\Model(array("data" => $categories, "limit" => 10, "page" => $numberPage));
     $page = $paginator->getPaginate();
     $this->view->setVar("page", $page);
 }
Пример #2
0
 public function indexAction()
 {
     if ($this->request->hasPost('od') && $this->request->getPost('od') == 'y') {
         $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
     }
     $zap = '';
     if ($this->request->hasPost('cat_id') && $this->request->isAjax()) {
         $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
         $cat_id = $this->request->getPost('cat_id');
         if (isset($cat_id) && is_numeric($cat_id)) {
             if ($this->request->hasPost('sub-cat')) {
                 $zap = "id = {$cat_id}";
                 $c_cat = 1;
             } else {
                 $zap = "id = {$cat_id} or id_sub = {$cat_id}";
                 $c_cat = 1;
             }
             foreach (Categories::find(array("{$zap}")) as $csv) {
                 $c_cat = $c_cat + $csv->proposal->count();
             }
             if ($c_cat == 1) {
                 $this->view->disable();
                 echo 1;
                 die;
             }
         }
     }
     ///////////////// Пагинация
     if (!empty($_POST['page'])) {
         $currentPage = $_POST["page"];
     } else {
         $currentPage = 1;
     }
     // Chat::find(array('order' => 'creation_date DESC'))
     if (empty($zap)) {
         $zaps = '';
     } else {
         $query = $this->modelsManager->createQuery("SELECT id FROM Categories WHERE " . $zap)->execute()->toArray();
         foreach ($query as $f) {
             $cats_id[] = $f['id'];
         }
         // $this->elements->var_print($cats_id);
         $sre = implode(" ,", $cats_id);
         $zaps = " category_id IN ({$sre})";
         // echo $zaps;
     }
     $bield = $this->modelsManager->createBuilder()->from('Proposal')->where($zaps)->orderBy('creation_date DESC');
     $paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $bield, "limit" => 10, "page" => $currentPage));
     $page = $paginator->getPaginate();
     foreach ($page->items as $prop) {
         foreach ($prop->dannproposal as $dann) {
             $props[$prop->id][$dann->fieldtype->id] = $dann->dann;
             $props[$prop->id]['cat'] = $prop->categories->name;
         }
     }
     $this->view->setVars(array('cl' => count($page->items), 'prop' => $props = isset($props) ? $props : false, 'page_num' => $page->current, 'page_total' => $page->total_pages));
 }
Пример #3
0
 public function getsubmenu()
 {
     $text = '';
     $tyc = Categories::find(array("id_sub > 0"));
     foreach ($tyc->toArray() as $category) {
         $text .= '<li ><a data-cat="' . $category['id'] . '" sub-cat="' . $category['id_sub'] . '">' . $category['name'] . ' </a> </li>';
     }
     return $text;
 }
 public function postDestory()
 {
     $category = Categories::find(Input::get('id'));
     if ($category) {
         $category->delete();
         return Redirect::to('admin/categories/index')->with('message', '刪除成功');
     }
     return Redirect::to('admin/categories/index')->with('message', '刪除失敗,請再試一次');
 }
Пример #5
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;
 }
Пример #6
0
 /**
  * Sets the category we are operating on
  *
  * @param Categories|integer $cat A category table or a numeric category ID
  *
  * @return void
  */
 protected function setCategory($cat)
 {
     // Initialise
     $this->category = null;
     $this->category_id = null;
     $this->folder = null;
     if ($cat instanceof Categories) {
         $this->category = $cat;
         $this->category_id = $cat->id;
     } elseif (is_numeric($cat)) {
         $this->category_id = (int) $cat;
         $container = Container::getInstance('com_ars');
         $this->category = $container->factory->model('Categories')->tmpInstance();
         $this->category->find($this->category_id);
     }
     // Store folder
     $folder = $this->category->directory;
     // Check for categories stored in Amazon S3
     $potentialPrefix = substr($folder, 0, 5);
     $potentialPrefix = strtolower($potentialPrefix);
     if ($potentialPrefix == 's3://') {
         // If it is stored on S3 make sure there are files stored with the given directory prefix
         $check = substr($folder, 5);
         $s3 = AmazonS3::getInstance();
         $items = $s3->getBucket('', $check . '/');
         if (empty($items)) {
             return;
         }
     } else {
         // If it is stored locally, make sure the folder exists
         \JLoader::import('joomla.filesystem.folder');
         if (!\JFolder::exists($folder)) {
             $folder = JPATH_ROOT . '/' . $folder;
             if (!\JFolder::exists($folder)) {
                 return;
             }
         }
     }
     $this->folder = $folder;
 }
Пример #7
0
 public function indexAction()
 {
     $orderBy = array("1" => "price asc", "2" => "price desc", "3" => "discount asc", "4" => "discount desc");
     $numberPage = 1;
     $query = Products::query();
     //            -> where("is_available=1");
     if ($this->request->isPost()) {
         // SEARCH
         $name = $this->request->getPost("name");
         $status = $this->request->getPost("status");
         $category = $this->request->getPost("category");
         $subcat = $this->request->getPost("subcat");
         $order = $this->request->getPost("order");
         if ($name != "") {
             $query->andWhere("name like '%{$name}%'");
         }
         if ($category != "") {
             $query->andWhere("category_id={$category}");
         }
         if ($subcat != "") {
             $query->andWhere("sub_category_id={$subcat}");
         }
         if ($order != "") {
             $query->order($orderBy[$order]);
         }
     }
     if (!$status || $status == "") {
         $status = 'New';
     }
     if ($status != "All") {
         $query->andWhere("status='{$status}'");
     }
     $numberPage = $this->request->getQuery("page", "int");
     $productList = $query->execute();
     $products = new Paginator(array("data" => $productList, "limit" => 10, "page" => $numberPage));
     $categories = Categories::find();
     $statusTypies = ["New", "Confirmed", "Enabled", "Disabled", "Approved"];
     $postData = $this->request->getPost();
     $subcats = SubCategories::find();
     $this->view->page = $products->getPaginate();
     $this->view->categories = $categories;
     $this->view->subcats = $subcats;
     $this->view->statusTypies = $statusTypies;
     $this->view->postData = $postData;
     $this->view->orderBy = $orderBy;
     $this->view->status = $status;
     $this->view->categoriesJson = json_encode(Categories::find()->toArray());
     $this->view->subCatsJson = json_encode($subcats->toArray());
 }
Пример #8
0
 public static function findByName($name)
 {
     $response = new Categories();
     if (!$name) {
         $response->status = $response::STATUS_BAD_REQUEST;
         $response->addError('NAME_IS_REQUIRED');
         return $response->toArray();
     }
     try {
         $response->data = Categories::find(['conditions' => 'name LIKE :name:', 'bind' => ['name' => '%' . $name . '%'], 'order' => 'name ASC'])->toArray();
     } catch (Exception $e) {
         $response->setException($e);
     } finally {
         return $response->toArray();
     }
 }
	public function indexAction()
	{
		$this->tag->prependTitle('Разделы');
		$this->view->setVar('h1', 'Разделы');
		
		$categories = Categories::find();

        $paginator = new Paginator(array(
            "data"  => $categories,
            "limit" => 10,
            "page"  => $this->request->getQuery("page", "int") ?: 1
        ));

        $this->view->page = $paginator->getPaginate();
		$this->view->elements = $categories;
	}
Пример #10
0
 public function update($id)
 {
     $rules = array('title' => 'sometimes|required|min:2|max:30');
     $messages = array('title.required' => 'Title is required.');
     $validator = Validator::make(Input::all(), $rules, $messages);
     if ($validator->fails()) {
         return $this->response(array('statusCode' => 400, 'statusDescription' => 'Bad Request', 'errors' => $validator->messages()->toJson()));
     } else {
         $title = Input::get('title');
         $parent_id = Input::get('parent_id');
         $status = Input::get('status');
         $is_featured = Input::get('is_featured');
         Categories::find($id)->update(array('title' => $title, 'parent_id' => $parent_id, 'is_featured' => $is_featured, 'status' => $status, 'updated_at' => date("Y-m-d H:i:s")));
         return $this->response(array('statusCode' => 100, 'statusDescription' => 'Success', 'message' => "Category Added Successfully"));
     }
 }
Пример #11
0
 /**
  * Edits a categorie
  *
  * @param string $id
  */
 public function editAction($id)
 {
     if (!$this->request->isPost()) {
         $subcat = SubCategories::findFirstByid($id);
         if (!$subcat) {
             $this->flash->error("SubCategory was not found");
             return $this->dispatcher->forward(array("controller" => "subcat", "action" => "index"));
         }
         $this->view->id = $subcat->id;
         $this->tag->setDefault("id", $subcat->id);
         $this->tag->setDefault("name", $subcat->name);
         $this->tag->setDefault("title", $subcat->title);
         $this->tag->setDefault("subtitle", $subcat->subtitle);
         $this->view->subcat = $subcat;
         $this->view->categories = Categories::find();
     }
 }
Пример #12
0
 public function authentificateAction()
 {
     if (!$this->getRequest()->isPost()) {
         return $this->_forward('index');
     }
     $form = $this->getForm();
     if (!$form->isValid($_POST)) {
         $this->view->form = $form;
         return $this->render('index');
     } else {
         $values = $form->getValues();
         $authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Registry::get('database'));
         $authAdapter->setTableName('users');
         $authAdapter->setIdentityColumn('Login');
         $authAdapter->setCredentialColumn('Password');
         $authAdapter->setIdentity($values['Login']);
         $authAdapter->setCredential($values['Password']);
         $select = $authAdapter->getDbSelect();
         $select->where('Active = 1');
         if ($authAdapter->authenticate()->getCode() == Zend_Auth_Result::SUCCESS) {
             $databaseTable = $authAdapter->getResultRowObject();
             Zend_Registry::get('database')->query('UPDATE users SET LastConnection = NOW() WHERE Id = "' . $databaseTable->Id . '"');
             $session = $this->session;
             if (isset($_COOKIE['PreviousCategory'])) {
                 $table = new Categories();
                 $row = $table->find($_COOKIE['PreviousCategory'])->current();
                 if (isset($row->Id)) {
                     $session->category = $row->Id;
                     $session->categoryName = $row->Name;
                 }
             }
             $session->access = true;
             $session->id = $databaseTable->Id;
             $session->lastName = $databaseTable->LastName;
             $session->firstName = $databaseTable->FirstName;
             $session->rights = new UsersRights($databaseTable->Status);
             $this->view->access = true;
             $this->_forward('home');
         } else {
             $this->view->message = '<div class="error">Identification incorrect : mauvais nom d\'utilisateur et/ou mot de passe.</div>';
             $this->view->form = $form;
             return $this->render('index');
         }
     }
 }
Пример #13
0
	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();		
		}
	}
Пример #14
0
 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));
     }
 }
Пример #15
0
 public function getCategory($cat_id)
 {
     return View::make('store.category')->with('product', Product::where('category_id', "=", "{$cat_id}")->paginate(6))->with('category', Categories::find($cat_id));
 }
Пример #16
0
 /**
  * testFindAllThreaded method
  *
  * @return void
  */
 public function testFindAllThreaded()
 {
     $this->loadFixtures('Category');
     $TestModel = new Categories();
     $result = $TestModel->find('threaded');
     $expected = array(array('Category' => array('id' => '1', 'parent_id' => '0', 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array(array('Category' => array('id' => '2', 'parent_id' => '1', 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array(array('Category' => array('id' => '7', 'parent_id' => '2', 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array()), array('Category' => array('id' => '8', 'parent_id' => '2', 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array()))), array('Category' => array('id' => '3', 'parent_id' => '1', 'name' => 'Category 1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array()))), array('Category' => array('id' => '4', 'parent_id' => '0', 'name' => 'Category 2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array()), array('Category' => array('id' => '5', 'parent_id' => '0', 'name' => 'Category 3', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array(array('Category' => array('id' => '6', 'parent_id' => '5', 'name' => 'Category 3.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array()))));
     $this->assertEquals($expected, $result);
     $result = $TestModel->find('threaded', array('conditions' => array('Category.name LIKE' => 'Category 1%')));
     $expected = array(array('Category' => array('id' => '1', 'parent_id' => '0', 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array(array('Category' => array('id' => '2', 'parent_id' => '1', 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array(array('Category' => array('id' => '7', 'parent_id' => '2', 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array()), array('Category' => array('id' => '8', 'parent_id' => '2', 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array()))), array('Category' => array('id' => '3', 'parent_id' => '1', 'name' => 'Category 1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array()))));
     $this->assertEquals($expected, $result);
     $result = $TestModel->find('threaded', array('fields' => 'id, parent_id, name'));
     $expected = array(array('Category' => array('id' => '1', 'parent_id' => '0', 'name' => 'Category 1'), 'children' => array(array('Category' => array('id' => '2', 'parent_id' => '1', 'name' => 'Category 1.1'), 'children' => array(array('Category' => array('id' => '7', 'parent_id' => '2', 'name' => 'Category 1.1.1'), 'children' => array()), array('Category' => array('id' => '8', 'parent_id' => '2', 'name' => 'Category 1.1.2'), 'children' => array()))), array('Category' => array('id' => '3', 'parent_id' => '1', 'name' => 'Category 1.2'), 'children' => array()))), array('Category' => array('id' => '4', 'parent_id' => '0', 'name' => 'Category 2'), 'children' => array()), array('Category' => array('id' => '5', 'parent_id' => '0', 'name' => 'Category 3'), 'children' => array(array('Category' => array('id' => '6', 'parent_id' => '5', 'name' => 'Category 3.1'), 'children' => array()))));
     $this->assertEquals($expected, $result);
     $result = $TestModel->find('threaded', array('order' => 'id DESC'));
     $expected = array(array('Category' => array('id' => 5, 'parent_id' => 0, 'name' => 'Category 3', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array(array('Category' => array('id' => 6, 'parent_id' => 5, 'name' => 'Category 3.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array()))), array('Category' => array('id' => 4, 'parent_id' => 0, 'name' => 'Category 2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array()), array('Category' => array('id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array(array('Category' => array('id' => 3, 'parent_id' => 1, 'name' => 'Category 1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array()), array('Category' => array('id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array(array('Category' => array('id' => '8', 'parent_id' => '2', 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array()), array('Category' => array('id' => '7', 'parent_id' => '2', 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array()))))));
     $this->assertEquals($expected, $result);
     $result = $TestModel->find('threaded', array('conditions' => array('Category.name LIKE' => 'Category 3%')));
     $expected = array(array('Category' => array('id' => '5', 'parent_id' => '0', 'name' => 'Category 3', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array(array('Category' => array('id' => '6', 'parent_id' => '5', 'name' => 'Category 3.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array()))));
     $this->assertEquals($expected, $result);
     $result = $TestModel->find('threaded', array('conditions' => array('Category.name LIKE' => 'Category 1.1%')));
     $expected = array(array('Category' => array('id' => '2', 'parent_id' => '1', 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array(array('Category' => array('id' => '7', 'parent_id' => '2', 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array()), array('Category' => array('id' => '8', 'parent_id' => '2', 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array()))));
     $this->assertEquals($expected, $result);
     $result = $TestModel->find('threaded', array('fields' => 'id, parent_id, name', 'conditions' => array('Category.id !=' => 2)));
     $expected = array(array('Category' => array('id' => '1', 'parent_id' => '0', 'name' => 'Category 1'), 'children' => array(array('Category' => array('id' => '3', 'parent_id' => '1', 'name' => 'Category 1.2'), 'children' => array()))), array('Category' => array('id' => '4', 'parent_id' => '0', 'name' => 'Category 2'), 'children' => array()), array('Category' => array('id' => '5', 'parent_id' => '0', 'name' => 'Category 3'), 'children' => array(array('Category' => array('id' => '6', 'parent_id' => '5', 'name' => 'Category 3.1'), 'children' => array()))));
     $this->assertEquals($expected, $result);
     $result = $TestModel->find('all', array('fields' => 'id, name, parent_id', 'conditions' => array('Category.id !=' => 1)));
     $expected = array(array('Category' => array('id' => '2', 'name' => 'Category 1.1', 'parent_id' => '1')), array('Category' => array('id' => '3', 'name' => 'Category 1.2', 'parent_id' => '1')), array('Category' => array('id' => '4', 'name' => 'Category 2', 'parent_id' => '0')), array('Category' => array('id' => '5', 'name' => 'Category 3', 'parent_id' => '0')), array('Category' => array('id' => '6', 'name' => 'Category 3.1', 'parent_id' => '5')), array('Category' => array('id' => '7', 'name' => 'Category 1.1.1', 'parent_id' => '2')), array('Category' => array('id' => '8', 'name' => 'Category 1.1.2', 'parent_id' => '2')));
     $this->assertEquals($expected, $result);
     $result = $TestModel->find('threaded', array('fields' => 'id, parent_id, name', 'conditions' => array('Category.id !=' => 1)));
     $expected = array(array('Category' => array('id' => '2', 'parent_id' => '1', 'name' => 'Category 1.1'), 'children' => array(array('Category' => array('id' => '7', 'parent_id' => '2', 'name' => 'Category 1.1.1'), 'children' => array()), array('Category' => array('id' => '8', 'parent_id' => '2', 'name' => 'Category 1.1.2'), 'children' => array()))), array('Category' => array('id' => '3', 'parent_id' => '1', 'name' => 'Category 1.2'), 'children' => array()));
     $this->assertEquals($expected, $result);
 }
Пример #17
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $rules = array('category' => 'required|Integer', 'condition' => 'required|Integer', 'name' => 'required', 'description' => 'required', 'donor' => 'required|Integer', 'orignal_price' => 'required|Numeric', 'price' => 'required|Numeric', 'image' => 'required', 'attributes' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return $this->response(array('statusCode' => 400, 'statusDescription' => 'Bad Request', 'errors' => $validator->messages()->toJson()));
     } else {
         $iGetInstitute = Donor::where('user_id', Input::get('donor'))->first();
         $product = Product::find($id)->update(array('products_price' => Input::get('price'), 'products_orginal_price' => Input::get('orignal_price'), 'brand' => Input::get('brand', NULL), 'products_status' => Input::get('products_status', 1), 'products_donar' => Input::get('donor'), 'condition' => Input::get('condition'), 'products_image' => Input::get('image'), 'gender' => Input::get('gender'), 'age_range' => Input::get('age_range'), 'collections_id' => Input::get('collections_id'), 'seasons_id' => Input::get('seasons_id'), 'types_id' => Input::get('types_id'), 'freshly_faved' => Input::get('freshly_faved'), 'institution_id' => $iGetInstitute->institution_id));
         //                $product->save();
         $category = Categories::find(Input::get('category'));
         $product = Product::find($id);
         //$product->productCategory()->save($category);
         Product::find($id)->productCategory()->detach();
         //updateExistingPivot($category->categories_id, array("categories_id"=>$category->categories_id),false);
         $product->productCategory()->save($category);
         if (Input::has('tags')) {
             Product::find($id)->productTags()->detach();
             $product = Product::find($id);
             $inptags = Input::get("tags");
             $tags = explode(",", $inptags);
             foreach ($tags as $key => $value) {
                 $ctag = Tags::find($value);
                 if ($ctag) {
                     $product->productTags()->save($ctag);
                 }
             }
         }
         $attributes = json_decode(Input::get("attributes"), TRUE);
         //$attribs = array();
         ProductsAttributes::where("products_id", $id)->delete();
         foreach ($attributes as $key => $value) {
             $opt_values = explode(",", $value);
             foreach ($opt_values as $optval) {
                 //echo $key." ".$optval."<br/>";
                 $attribute = new ProductsAttributes(array('options_id' => $key, 'options_values_id' => $optval));
                 $product->productsAttributes()->save($attribute);
             }
         }
         $description = ProductsDescription::find($id)->update(array("products_name" => Input::get("name"), "products_description" => Input::get("description")));
         //$product->productsDescription()->save($description);
         return $this->response(array('statusCode' => 100, 'statusDescription' => 'Success'));
     }
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $issue = Issue::find($id);
     if ($issue == NULL) {
         throw new Exception('Invalid Book ID');
     }
     $issue->added_at_timestamp = date('d-M-y h:i A', strtotime($issue->added_at_timestamp));
     $book = Books::find($issue->book_id);
     $issue->book_name = $book->title;
     $issue->author = $book->author;
     $issue->category = Categories::find($book->category_id)->category;
     $issue->available_status = (bool) $issue->available_status;
     if ($issue->available_status == 1) {
         return $issue;
     }
     $conditions = array('return_time' => 0, 'book_issue_id' => $id);
     $book_issue_log = Logs::where($conditions)->take(1)->get();
     foreach ($book_issue_log as $log) {
         $student_id = $log->student_id;
     }
     $student_data = Student::find($student_id);
     unset($student_data->email_id);
     unset($student_data->books_issued);
     unset($student_data->approved);
     unset($student_data->rejected);
     $student_branch = Branch::find($student_data->branch)->branch;
     $roll_num = $student_data->roll_num . '/' . $student_branch . '/' . substr($student_data->year, 2, 4);
     unset($student_data->roll_num);
     unset($student_data->branch);
     unset($student_data->year);
     $student_data->roll_num = $roll_num;
     $student_data->category = StudentCategories::find($student_data->category)->category;
     $issue->student = $student_data;
     return $issue;
 }
Пример #19
0
 public function testBehaviorsNestedSet()
 {
     require 'unit-tests/config.db.php';
     if (empty($configMysql)) {
         $this->markTestSkipped("Test skipped");
         return;
     }
     $this->_prepareDI();
     $cars = new Categories();
     $cars->title = 'Cars';
     $this->assertTrue($cars->saveNode());
     $phones = new Categories();
     $phones->title = 'Mobile phones';
     $this->assertTrue($phones->saveNode());
     $ford = new Categories();
     $ford->title = 'Ford';
     $this->assertTrue($ford->appendTo($cars));
     $mercedes = new Categories();
     $mercedes->title = 'Mercedes';
     $this->assertTrue($mercedes->insertBefore($ford));
     $audi = new Categories();
     $audi->title = 'Audi';
     $this->assertTrue($audi->prependTo($cars));
     $samsung = new Categories();
     $samsung->title = 'Samsung';
     $this->assertTrue($samsung->appendTo($phones));
     $motorola = new Categories();
     $motorola->title = 'Motorola';
     $this->assertTrue($motorola->insertAfter($samsung));
     $iphone = new Categories();
     $iphone->title = 'iPhone';
     $this->assertTrue($iphone->insertBefore($samsung));
     $data = array(array("id" => 1, "root" => 1, "lft" => 1, "rgt" => 8, "lvl" => 1, "title" => "Cars"), array("id" => 5, "root" => 1, "lft" => 2, "rgt" => 3, "lvl" => 2, "title" => "Audi"), array("id" => 4, "root" => 1, "lft" => 4, "rgt" => 5, "lvl" => 2, "title" => "Mercedes"), array("id" => 3, "root" => 1, "lft" => 6, "rgt" => 7, "lvl" => 2, "title" => "Ford"), array("id" => 2, "root" => 2, "lft" => 1, "rgt" => 8, "lvl" => 1, "title" => "Mobile phones"), array("id" => 8, "root" => 2, "lft" => 2, "rgt" => 3, "lvl" => 2, "title" => "iPhone"), array("id" => 6, "root" => 2, "lft" => 4, "rgt" => 5, "lvl" => 2, "title" => "Samsung"), array("id" => 7, "root" => 2, "lft" => 6, "rgt" => 7, "lvl" => 2, "title" => "Motorola"));
     $categories = Categories::find(array('order' => 'root, lft'));
     $this->assertEquals($data, $categories->toArray());
 }
			<section class="padd-tb-60 bg-dark image-v2 bg-fixed">

				<div class="container">

					<div class="row">

						<div class="col-md-4 col-md-offset-4">
							<div class="panel panel-default">
								<div class="panel-heading">
									<h3 class="panel-title">Product Details</h3>
								</div>
								<div class="panel-body">
									<?php 
$supplier = Suppliers::find($product->supplierId);
$category = Categories::find($product->categoryId);
?>
									<p>Product ID: {{$product->supplierProductId}}</p>
									<p>Name: {{$product->name}}</p>
									<p>Supplier: {{$supplier->name}}</p>
									<p>Category: {{$category->name}}</p>
									<p>Cost: {{$product->unitPrice}}</p>
									<p>Quantity:  {{$product->quantity}}<br></p>
									<p>Color is: {{$product->color}}</p>
									<p>Description is: {{$product->details}}</p>

									<div class="padd-t-20">
											<a class="btn btn-small btn-green" href="{{ URL::to('suppliers/' . $product->id . '/edit') }}">Edit</a>
											{{ Form::open(array('url' => 'products/' . $product->id, 'class' => 'pull-right')) }}
            								{{ Form::hidden('_method', 'DELETE') }}
            								{{ Form::submit('Delete', array('class' => 'btn btn-danger', 'onclick' => 'return confirm("Are you sure you want to delete this product?")')) }}
												<tr>
													<th><h4>Name</h4></th>
													<th><h4>Cost</h4></th>
													<th><h4>Supplier</h4></th>
													<th><h4>Category</h4></th>
													<th><h4>Quantity</h4></th>
													<th><h4>Colour</h4></th>
													<th><h4>Status</h4></th>
												</tr>
											</thead>
											<tbody>							
												@foreach($products as $key => $value)
												<tr>
													<?php 
$supplier = Suppliers::find($value->supplierId);
$category = Categories::find($value->categoryId);
?>
													<td style="width:15%"><strong>{{ $value->name }}</strong></td>
													<td style="width:15%">{{ $value->unitPrice}}</td>
													<td style="width:15%">{{ $supplier->name}}</td>
													<td style="width:15%">{{ $category->name}}</td>
													<td style="width:15%">{{ $value->quantity}}</td>
													<td style="width:10%">{{ $value->color}}</td>
													<td style="width:5%"><a class="btn btn-small btn-blue" href="{{ URL::to('products/' . $value->id . '/details') }}">Details</a></td>
													<td style="width:5%"><a class="btn btn-small btn-green" href="{{ URL::to('products/' . $value->id . '/edit') }}">Edit</a></td>
													<td style="width:5%">
													{{ Form::open(array('url' => 'products/' . $value->id, 'class' => 'pull-right')) }}
                    									{{ Form::hidden('_method', 'DELETE') }}
                    									{{ Form::submit('Delete', array('class' => 'btn btn-danger', 'onclick' => 'return confirm("Are you sure you want to delete this product?")')) }}
                										{{ Form::close() }}
												</td>
Пример #22
0
 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));
     }
 }
Пример #23
0
 public function indexAction()
 {
     $this->view->categories = Categories::find();
 }
Пример #24
0
 function providerSignupAction()
 {
     if ($this->request->isPost()) {
         $name = $this->request->getPost('name');
         $email = $this->request->getPost('email');
         $password = $this->request->getPost('password');
         $cpassword = $this->request->getPost('cpassword');
         $timezone = $this->request->getPost('timezone');
         $phone = $this->request->getPost('phone');
         $address = $this->request->getPost('address');
         $categories = $this->request->getPost('categories');
         $membership = $this->request->getPost('membership');
         $card_token = $this->request->getPost('card_token');
         $errors = array();
         $fields = array('name', 'email', 'password', 'cpassword', 'phone', 'address', 'membership', 'card_token');
         $fieldsEntered = 0;
         foreach ($fields as $field) {
             if (trim(${$field}) != '') {
                 $fieldsEntered++;
             }
         }
         if ($fieldsEntered < count($fields)) {
             array_push($errors, "Some fields were not entered.");
         }
         if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
             array_push($errors, "Email is invalid.");
         }
         if (strlen($password) < 6) {
             array_push($errors, "Password must be at least 6 characters long.");
         }
         if ($password != $cpassword) {
             array_push($errors, "Passwords don't match.");
         }
         if (!preg_match('/^\\(?[0-9]{3}\\)?|[0-9]{3}[-. ]? [0-9]{3}[-. ]?[0-9]{4}$/', $phone)) {
             array_push($errors, "Invalid phone number format.");
         }
         $apiLink = $this->config->maps->api_link;
         $geoData = file_get_contents($apiLink . urlencode($address));
         if ($geoData === FALSE) {
             array_push($errors, "Invalid address.");
         }
         $provider = Providers::findFirst("email = '{$email}'");
         if ($provider) {
             array_push($errors, "Email is already taken.");
         }
         if (!count($errors)) {
             $salt = bin2hex(openssl_random_pseudo_bytes(16, $cstrong));
             $provider = new Providers();
             $provider->name = $name;
             $provider->email = $email;
             $provider->salt = $salt;
             $provider->password = md5($salt . $password);
             $provider->timezone = $timezone;
             $provider->membership = $membership;
             require_once "../vendor/stripe-php-master/init.php";
             \Stripe\Stripe::setApiKey($this->config->stripe->secret_key);
             $plan = Memberships::findFirst("id = '{$membership}'");
             $amount = (int) $plan->total * 100;
             $duration = $plan->duration;
             $date = new DateTime(date());
             $date->add(new DateInterval('P' . $duration . 'M'));
             $provider->expiry_date = $date->format('Y-m-d H:i:s');
             $account = \Stripe\Account::create(array("managed" => true, "country" => "US"));
             $provider->stripe_account_token = $account->id;
             $customer = \Stripe\Customer::create(array("description" => $name, "email" => $email, "source" => $card_token));
             $provider->stripe_customer_token = $customer->id;
             $provider->stripe_card_token = $customer->default_source;
             $providerPhone = new ProviderPhones();
             $providerPhone->telephone = $phone;
             $provider->providerPhones = $providerPhone;
             $providerAddress = new ProviderAddresses();
             $geoJSON = json_decode($geoData);
             if ($geoJSON->status == "OK") {
                 $geometry = $geoJSON->results[0]->geometry->location;
                 $lat = $geometry->lat;
                 $lng = $geometry->lng;
             } else {
                 $lat = 0;
                 $lng = 0;
             }
             $providerAddress->latitude = $lat;
             $providerAddress->longitude = $lng;
             $providerAddress->address = $address;
             $provider->providerAddresses = $providerAddress;
             $providerCategories = array();
             foreach ($categories as $category) {
                 $providerCategory = new ProviderCategories();
                 $providerCategory->cid = $category;
                 array_push($providerCategories, $providerCategory);
             }
             $provider->providerCategories = $providerCategories;
             if ($provider->create()) {
                 \Stripe\Charge::create(array("amount" => $amount, "currency" => "usd", "customer" => $provider->stripe_customer_token, "source" => $provider->stripe_card_token, "description" => "{$plan->name} plan subscription"));
                 $this->response->redirect('/login?success');
                 $this->view->disable();
             } else {
                 array_push($errors, "An error occurred during the signup process.");
             }
         }
         $this->view->errors = $errors;
     }
     $timezones = (require "../app/config/timezones.php");
     $this->view->timezones = $timezones;
     $memberships = Memberships::find("id > 1");
     $this->view->memberships = $memberships;
     $categories = Categories::find();
     $this->view->categories = $categories;
     echo $this->view->render('auth', 'providerSignup');
 }
Пример #25
0
 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));
     }
 }
Пример #26
0
 public function getDelete($id = '')
 {
     if ($id == '') {
         return Redirect::to($this->route)->with('msg_error', Lang::get('messages.categories_display_err'));
     } else {
         $category = Categories::find($id);
         $delete = Categories::destroy($id);
         if (!$delete) {
             return Redirect::to($this->route . '/trash')->with('msg_error', Lang::get('messages.categories_delete_err', array('title' => $category->title)));
         } else {
             return Redirect::to($this->route . '/trash')->with('msg_success', Lang::get('messages.categories_delete', array('title' => $category->title)));
         }
     }
 }
Пример #27
0
<div class="categories">
<?php 
foreach (Categories::find("status = 1") as $category) {
    echo "<span class='category'>", $category->name, "</span>";
}
?>
</div>

Пример #28
0
 public function setcategoryAction()
 {
     $form = new Zend_Form();
     $form->setAction(PUBLIC_PATH . $this->getRequest()->getControllerName() . '/setcategory/');
     $form->setMethod('post');
     $form->setAttrib('id', 'CategoryForm');
     $type = new Zend_Form_Element_Select('Categorie');
     //$type->setLabel('Choisissez la catégorie de vos saisies');
     $type->setRequired(true);
     $table = new Categories();
     $select = $table->select();
     $objects = $table->fetchAll($select);
     foreach ($objects as $object) {
         $type->addMultiOption($object->Id, $object->Name);
     }
     if (!empty($this->session->category)) {
         $type->setValue($this->session->category);
     } else {
         $type->setValue($objects[0]->Id);
     }
     $type->setDecorators(array('ViewHelper', 'Description', 'Errors', array('HtmlTag', array('tag' => 'dd', 'class' => 'PositionCenter'))));
     $submit = new Zend_Form_Element_Submit('Enregistrer');
     $form->addElement($type);
     $form->addElement($submit);
     if ($this->getRequest()->isPost() && $form->isValid($_POST)) {
         $values = $form->getValues();
         $row = $table->find($values['Categorie'])->current();
         unset($_COOKIE['PreviousCategory']);
         setcookie('PreviousCategory', $row->Id, time() + 365 * 24 * 60 * 60, '/');
         $this->session->category = $row->Id;
         $this->session->categoryName = $row->Name;
         $this->session->message = '<div class = "success">Vos saisies seront désormais pris en compte et rentrés dans la catégorie <strong>' . $row->Name . '</strong></div>';
         return $this->_forward('index');
     } else {
         $this->rememberCategory();
         $this->view->message .= '<div class = "notice">Choisissez le métier sur lequel vous souhaitez travailler</div>';
         $this->view->form = $form;
         return $this->render('form');
     }
 }
Пример #29
0
<?php

error_reporting(E_ALL);
require 'app/config/config.php';
$modelManager = new Phalcon\Model\Manager();
$modelManager->setModelsDir(__DIR__ . '/' . $config->phalcon->modelsDir);
Phalcon\Db\Pool::setDefaultDescriptor($config->database);
$categoriesCode = array();
foreach (Categories::find() as $category) {
    $categoriesCode[$category->name] = $category->id;
}
foreach (News::find() as $new) {
    foreach ($new->getNewsCategories() as $newCategory) {
        $newCategory->delete();
    }
    $categories = array();
    if (stripos($new->title, 'conf') !== false) {
        $categories['conf'] = true;
    }
    if (stripos($new->title, 'world') !== false) {
        $categories['conf'] = true;
    }
    if (stripos($new->title, 'Rio') !== false) {
        $categories['conf'] = true;
    }
    if (stripos($new->title, 'phpDay') !== false) {
        $categories['conf'] = true;
    }
    if (stripos($new->title, 'NW') !== false) {
        $categories['conf'] = true;
    }
 public function show($id)
 {
     $category = Categories::find($id);
     return View::make('categories.show')->with('category', $category);
 }