public function gallery_upload($cid, $uid) { //if (!$this->loginmanager->is_logged_in()) //show_error('You are not logged in!', 403); $content = Content::factory((int) $cid); $u = User::factory((int) $uid); $config['upload_path'] = "iu-assets/galleries/"; $config['allowed_types'] = 'png|jpg|jpeg|jpe|gif'; $this->load->library('upload', $config); //file_put_contents('uploadify', json_encode($_FILES)); if (!$this->upload->do_upload("Filedata")) { $error = $this->upload->display_errors(); // do stuff show_error('Couldn\'t upload!', 500); } else { $data = $this->upload->data(); $gi = new GalleryItem(); $gi->image = $config['upload_path'] . $data['file_name']; $gi->order = 0; $gi->save(array($content, $content->page->get()->user->get())); $content->updated = time(); $content->save(); } echo 'OK!'; }
public function beforeSave() { $mapper = Manager::getInstance()->getMapper($this->mapper_alias); $categoryMapper = Manager::getInstance()->getMapper($this->category_mapper_alias); $aContainer = $mapper->getContainer(); if (!$this->getOwner()->getGalleryId()) { // Создаем галерею $oCategory = new GalleryCategory(); $oCategory->setName($this->getOwner()->getName()); $oCategory->setAlias(StringHelper::translit($this->getOwner()->getName())); $oCategory->setIsSystem(1); $oCategory->setIsActive(1); $categoryId = $oCategory->save(); $this->getOwner()->setGalleryId($categoryId); } else { $categoryId = $this->getOwner()->getGalleryId(); $oCategory = $categoryMapper->findById($categoryId); } // Удаляем все записи о фотках из базы $oQuery = new DbUpdater(DbUpdater::TYPE_DELETE, $aContainer['TableName'], $aContainer['Object'], $this->getDbConnectionAlias()); $oCriteria = new CriteriaElement('category_id', Criteria::EQUAL, $categoryId); $oQuery->addCriteria($mapper->parseUpdateCriteria($oCriteria->renderWhere())); $oQuery->delete(); // Добавляем фотки $images = $this->getOwner()->getImages(); $images_names = $this->getOwner()->getImagesNames(); if (is_array($images) && count($images)) { foreach ($images as $k => $image) { // Добавляем фотки $oImage = new GalleryItem(); $oImage->setName($images_names[$k]); $oImage->setAlias($image); $oImage->setCategoryId($categoryId); $oImage->setPos($k + 1); $oImage->setIsActive(1); $oImage->save(); } // set cover $oCategory->setCover($images[0]); $oCategory->save(); } // done return true; }