Ejemplo n.º 1
0
 /**
  * @param Phalcon\Mvc\ModelInstance $entity
  * @param array $options
  */
 public function initialize($entity = null, $options = null)
 {
     if (!isset($options['edit']) && !isset($options['create'])) {
         $id = new Text('id');
         $id->setLabel('Id');
         $this->add($id);
     }
     $category = new Select('categoriesId', Categories::find(), array('using' => array('id', 'name'), 'useEmpty' => true, 'emptyText' => '...'));
     $category->setLabel('Category');
     $category->addValidator(new PresenceOf(array('message' => 'Category is mandatory')));
     $category->setUserOption('searcheable', true);
     $category->setUserOption('browseable', true);
     $category->setUserOption('relation', 'category');
     $this->add($category);
     $icon = new Text('icon', array('placeholder' => 'Enter a css-icon class name'));
     $icon->setLabel('Icon');
     $icon->addValidator(new PresenceOf(array('message' => 'Icon is mandatory')));
     $this->add($icon);
     $code = new Text('code', array('maxlength' => 10));
     $code->setLabel('Code');
     $code->setUserOption('searcheable', true);
     $code->setUserOption('browseable', true);
     $code->addValidator(new PresenceOf(array('message' => 'Code is mandatory')));
     $this->add($code);
     $name = new Text('name', array('maxlength' => 64));
     $name->setLabel('Name');
     $name->setUserOption('searcheable', true);
     $name->setUserOption('browseable', true);
     $name->addValidator(new PresenceOf(array('message' => 'Name is mandatory')));
     $this->add($name);
     $description = new TextArea('description');
     $description->setLabel('Description');
     $description->addValidator(new PresenceOf(array('message' => 'Description is mandatory')));
     $this->add($description);
     $price = new Text('price');
     $price->setLabel('Price');
     $price->setUserOption('searcheable', true);
     $price->setUserOption('browseable', true);
     $price->addValidator(new PresenceOf(array('message' => 'Price is mandatory')));
     $price->addValidator(new Numericality(array('message' => 'Price must be a number')));
     $this->add($price);
     $stock = new Text('stock');
     $stock->setLabel('Stock');
     $stock->setUserOption('browseable', true);
     $stock->addValidator(new PresenceOf(array('message' => 'Current stock is mandatory')));
     $stock->addValidator(new Numericality(array('message' => 'Current stock must be a number')));
     $this->add($stock);
     if (isset($options['edit'])) {
         $createdAt = new Date('created', array('readonly' => 'readonly'));
         $createdAt->setLabel('Created At');
         if ($entity->createdAt) {
             $entity->created = date('Y-m-d', $entity->createdAt);
         }
         $this->add($createdAt);
     }
 }
Ejemplo n.º 2
0
 /**
  * @Get("/category/{short-name:[a-z]+}", name="show-category")
  */
 public function categoryAction($shortName = null)
 {
     $category = Categories::findFirstByShortName($shortName);
     if (!$category) {
         return $this->dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
     }
     switch ($this->request->getQuery("order")) {
         case 'newest':
             $products = $category->products;
             break;
         case 'price':
             $products = $category->getProducts(array('order' => 'price'));
             break;
         case 'name':
             $products = $category->getProducts(array('order' => 'name'));
             break;
         default:
             $products = $category->products;
     }
     $paginator = new Paginator(array("data" => $products, "limit" => 4, "page" => $this->request->getQuery("page", null, 1)));
     $this->view->category = $category;
     $this->view->page = $paginator->getPaginate();
     $this->tag->setTitle($category->name);
 }