Esempio n. 1
0
 /**
  * Adds a category
  * 
  * @param array $input Raw input data
  * @return boolean
  */
 public function add(array $input)
 {
     $input = $this->prepareInput($input);
     // Form data reference
     $category =& $input['data']['category'];
     $category['web_page_id'] = '';
     // If we have a cover, then we need to upload it
     if (!empty($input['files']['file'])) {
         $file =& $input['files']['file'];
         $this->filterFileInput($file);
         // Override empty cover's value now
         $category['cover'] = $file[0]->getName();
     }
     if ($this->categoryMapper->insert(ArrayUtils::arrayWithout($category, array('menu', 'slug')))) {
         $id = $this->getLastId();
         $this->track('Category "%s" has been created', $category['name']);
         // If there's a file, then it needs to uploaded as a cover
         if (!empty($input['files']['file'])) {
             $this->imageManager->upload($id, $input['files']['file']);
         }
         // Add a web page now
         if ($this->webPageManager->add($id, $category['slug'], 'Blog (Categories)', 'Blog:Category@indexAction', $this->categoryMapper)) {
             // Do the work in case menu widget was injected
             if ($this->hasMenuWidget()) {
                 $this->addMenuItem($this->webPageManager->getLastId(), $category['name'], $input);
             }
         }
         return true;
     } else {
         return false;
     }
 }
Esempio n. 2
0
 /**
  * Adds an album
  * 
  * @param array $input Raw input data
  * @return boolean
  */
 public function add(array $input)
 {
     $input = $this->prepareInput($input);
     $form =& $input['data']['album'];
     // Default empty values
     $form['web_page_id'] = '';
     $form['cover'] = '';
     // If we have a cover, then we need to upload it
     if (!empty($input['files']['file'])) {
         $file =& $input['files']['file'];
         $this->filterFileInput($file);
         // Override empty cover's value now
         $form['cover'] = $file[0]->getName();
     }
     if ($this->albumMapper->insert(ArrayUtils::arrayWithout($form, array('slug', 'menu')))) {
         $id = $this->getLastId();
         // If there's a file, then it needs to uploaded as a cover
         if (!empty($input['files']['file'])) {
             $this->albumPhoto->upload($id, $input['files']['file']);
         }
         $this->track('Album "%s" has been created', $form['name']);
         if ($this->webPageManager->add($this->getLastId(), $form['slug'], 'Photogallery', 'Photogallery:Album@showAction', $this->albumMapper)) {
             // Do the work in case menu widget was injected
             if ($this->hasMenuWidget()) {
                 $this->addMenuItem($this->webPageManager->getLastId(), $form['name'], $input);
             }
         }
         return true;
     } else {
         return false;
     }
 }
Esempio n. 3
0
 /**
  * Adds a product
  * 
  * @param array $input Raw input data
  * @return boolean
  */
 public function add(array $input)
 {
     $input = $this->prepareInput($input);
     // Short-cuts
     $product =& $input['data']['product'];
     // Initial view count
     $product['views'] = 0;
     // For cross-database compatibility, the date must be generated here, not in the mapper
     $product['date'] = date('Y-m-d', time());
     $files =& $input['files']['file'];
     // Insert should be first, because we need to provide an id
     $this->productMapper->insert(ArrayUtils::arrayWithout($product, array('slug')));
     // After insert, now we can get an id
     $id = $this->getLastId();
     // Do we have images?
     if (!empty($files)) {
         // So let's first try to upload them
         if ($this->imageManager->upload($id, $files)) {
             // And write their base names into storage
             foreach ($files as $file) {
                 $this->imageMapper->insert($id, $file->getName(), 0, true);
             }
         } else {
             trigger_error('Failed to upload product additional image', E_USER_NOTICE);
         }
     }
     $this->track('Product "%s" has been added', $product['name']);
     // Add a web page now
     return $this->webPageManager->add($id, $product['slug'], 'Shop (Products)', 'Shop:Product@indexAction', $this->productMapper);
 }
Esempio n. 4
0
 /**
  * Adds a page
  * 
  * @param array $input Raw input data
  * @return boolean
  */
 public function add(array $input)
 {
     $input = $this->prepareInput($input);
     $page =& $input['page'];
     $page['web_page_id'] = '';
     if (!$this->pageMapper->insert(ArrayUtils::arrayWithout($page, array('controller', 'makeDefault', 'slug', 'menu')))) {
         return false;
     } else {
         // It was inserted successfully
         $id = $this->getLastId();
         // If checkbox was checked
         if (isset($page['makeDefault']) && $page['makeDefault'] == '1') {
             $this->makeDefault($id);
         }
         // Use custom controller if provided by user
         $controller = isset($page['controller']) ? $page['controller'] : 'Pages:Page@indexAction';
         // Add a web page now
         if ($this->webPageManager->add($id, $page['slug'], 'Pages', $controller, $this->pageMapper)) {
             // Do the work in case menu widget was injected
             if ($this->hasMenuWidget()) {
                 $this->addMenuItem($this->webPageManager->getLastId(), $page['name'], $input);
             }
         }
         // Track it
         $this->track('A new "%s" page has been created', $page['name']);
         return true;
     }
 }
Esempio n. 5
0
 /**
  * Adds an announce
  * 
  * @param array $input Raw input data
  * @return boolean
  */
 public function add(array $input)
 {
     $input = $this->prepareInput($input);
     $input['web_page_id'] = '';
     $this->announceMapper->insert(ArrayUtils::arrayWithout($input, array('slug')));
     $id = $this->getLastId();
     $this->track('Announce "%s" has been added', $input['name']);
     $this->webPageManager->add($id, $input['slug'], 'Announcements', 'Announcement:Announce@indexAction', $this->announceMapper);
     return true;
 }
Esempio n. 6
0
 /**
  * Adds a post
  * 
  * @param array $input Raw input data
  * @return boolean
  */
 public function add(array $input)
 {
     $input = $this->prepareInput($input);
     $input['web_page_id'] = '';
     $input['views'] = '0';
     if ($this->postMapper->insert(ArrayUtils::arrayWithout($input, array('date', 'slug')))) {
         $id = $this->getLastId();
         $this->track('Post "%s" has been added', $input['name']);
         $this->webPageManager->add($id, $input['slug'], 'Blog (Posts)', 'Blog:Post@indexAction', $this->postMapper);
     }
     return true;
 }
Esempio n. 7
0
 /**
  * Adds a form
  * 
  * @param array $input Raw input data
  * @return boolean
  */
 public function add(array $input)
 {
     $input = $this->prepareInput($input);
     $form =& $input['form'];
     $form['web_page_id'] = '';
     if ($this->formMapper->insert(ArrayUtils::arrayWithout($form, array('slug', 'menu')))) {
         // Add a web page now
         if ($this->webPageManager->add($this->getLastId(), $form['slug'], 'Mail forms', 'MailForm:Form@indexAction', $this->formMapper)) {
             if ($this->hasMenuWidget()) {
                 $this->addMenuItem($this->webPageManager->getLastId(), $form['name'], $input);
             }
         }
         $this->track('Mail form "%s" has been created', $form['name']);
         return true;
     } else {
         return false;
     }
     return true;
 }
Esempio n. 8
0
 /**
  * Adds a category
  * 
  * @param array $input Raw input data
  * @return boolean Depending on success
  */
 public function add(array $input)
 {
     $input = $this->prepareInput($input);
     $category =& $input['category'];
     $category['web_page_id'] = '';
     if ($this->categoryMapper->insert(ArrayUtils::arrayWithout($category, array('slug', 'menu')))) {
         $this->track('Category "%s" has been created', $category['name']);
         if ($this->webPageManager->add($this->getLastId(), $category['slug'], 'News (Categories)', 'News:Category@indexAction', $this->categoryMapper)) {
             if ($this->hasMenuWidget()) {
                 // If at least one menu widget it added
                 if (isset($input['menu']['widget']) && is_array($input['menu']['widget'])) {
                     $this->addMenuItem($this->webPageManager->getLastId(), $category['name'], $input);
                 }
             }
         }
         return true;
     } else {
         return false;
     }
 }
Esempio n. 9
0
 /**
  * Adds a post
  * 
  * @param array $input Raw input data
  * @return boolean Depending on success
  */
 public function add(array $input)
 {
     $input = $this->prepareInput($input);
     $data =& $input['data']['post'];
     // By default there are 0 views
     $data['views'] = 0;
     // Handle cover
     if (!empty($input['files']['file'])) {
         $file =& $input['files']['file'];
         $this->filterFileInput($file);
         $data['cover'] = $file[0]->getName();
     } else {
         $data['cover'] = '';
     }
     $this->postMapper->insert(ArrayUtils::arrayWithout($data, array('date', 'slug')));
     // Not sure about this one
     if (!empty($input['files'])) {
         $file =& $input['files']['file'];
         $this->imageManager->upload($this->getLastId(), $file);
     }
     $this->track('New post "%s" has been created', $data['name']);
     $this->webPageManager->add($this->getLastId(), $data['slug'], 'News (Posts)', 'News:Post@indexAction', $this->postMapper);
     return true;
 }