Example #1
0
 public function save($data)
 {
     // always set state is unpublish for each save
     $data['state'] = 0;
     $id = $data['id'];
     if (isset($id) && (int) $id > 0) {
         if (!FrontJntHanhphucHelper::checkUserPermissionOnItem($id, '#__hp_albums')) {
             exit('Cannot edit this album!');
         }
     }
     if (parent::save($data)) {
         $id = (int) $this->getState($this->getName() . '.id');
         // Update images
         $currentImages = isset($_POST['current_images']) ? $_POST['current_images'] : array();
         $currentDesc = isset($_POST['current_desc']) ? $_POST['current_desc'] : array();
         Jnt_HanhPhucHelper::updateImages($id, $currentImages, $currentDesc, 'albums');
         // Temp files
         if (isset($_POST['tmp_other_img'])) {
             // Copy file
             Jnt_HanhPhucHelper::copyTempFiles($id, $_POST['tmp_other_img'], 'albums');
             // Insert images
             Jnt_HanhPhucHelper::insertImages($id, $_POST['tmp_other_img'], $_POST['tmp_desc'], 'albums');
         }
         if ($id) {
             $data['id'] = $id;
         }
         $delImage = isset($data['del_image']) ? $data['del_image'] : null;
         // Upload thumb
         $item = $this->getItem();
         $data['images'] = Jnt_HanhPhucHelper::uploadImages('images', $item, $delImage, 'albums', 300);
         return parent::save($data);
     }
     return false;
 }