Ejemplo n.º 1
0
 public function addLinks()
 {
     $link = new Weblink_Model_Weblink_Link();
     $links = $link->findAll(array('weblink_id' => $this->getId()));
     $this->setLinks($links);
     return $this;
 }
Ejemplo n.º 2
0
 public function copyTo($option)
 {
     $old_weblink_id = $this->getId();
     $this->setId(null)->setValueId($option->getId());
     if ($image_url = $this->getCoverUrl()) {
         $file = pathinfo($image_url);
         $filename = $file['basename'];
         $relativePath = $option->getRelativePath();
         $folder = Core_Model_Directory::getBasePathTo(Application_Model_Application::PATH_IMAGE . '/' . $relativePath);
         if (!is_dir($folder)) {
             mkdir($folder, 0777, true);
         }
         $img_src = Core_Model_Directory::getBasePathTo($image_url);
         $img_dst = $folder . '/' . $filename;
         if (@copy($img_src, $img_dst)) {
             $this->setImage($relativePath . '/' . $filename);
         }
     }
     $this->save();
     $link = new Weblink_Model_Weblink_Link();
     $links = $link->findAll(array('weblink_id' => $old_weblink_id));
     foreach ($links as $link) {
         $link->setId(null)->setWeblinkId($this->getId())->save();
     }
     return $this;
 }
Ejemplo n.º 3
0
 public function addLinks()
 {
     $link = new Weblink_Model_Weblink_Link();
     if ($this->getId()) {
         $link->find($this->getId(), 'weblink_id');
     }
     $this->setLink($link);
     return $this;
 }
Ejemplo n.º 4
0
 public function copyTo($option)
 {
     $old_weblink_id = $this->getId();
     $this->setId(null)->setValueId($option->getId())->save();
     $link = new Weblink_Model_Weblink_Link();
     $links = $link->findAll(array('weblink_id' => $old_weblink_id));
     foreach ($links as $link) {
         $link->setId(null)->setWeblinkId($this->getId())->save();
     }
     return $this;
 }
Ejemplo n.º 5
0
 public function editpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             $isNew = false;
             $application = $this->getApplication();
             // Test s'il y a un value_id
             if (empty($datas['value_id'])) {
                 throw new Exception($this->_('An error occurred while saving. Please try again later.'));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             $html = array('success' => '1', 'success_message' => $this->_('Link has been successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
             // Prépare la weblink
             $weblink = $option_value->getObject();
             if (!$weblink->getId()) {
                 $weblink->setValueId($datas['value_id']);
             }
             // S'il y a une cover image
             if (!empty($datas['file'])) {
                 if (!empty($datas['file'])) {
                     $relative_path = '/weblink/cover/';
                     $folder = Application_Model_Application::getBaseImagePath() . $relative_path;
                     $path = Application_Model_Application::getBaseImagePath() . $relative_path;
                     $file = Core_Model_Directory::getTmpDirectory(true) . '/' . $datas['file'];
                     if (!is_dir($path)) {
                         mkdir($path, 0777, true);
                     }
                     if (!copy($file, $folder . $datas['file'])) {
                         throw new exception($this->_('An error occurred while saving your picture. Please try againg later.'));
                     } else {
                         $weblink->setCover($relative_path . $datas['file']);
                     }
                     if (empty($datas['link'])) {
                         $html['success_message'] = $this->_("The image has been successfully saved");
                     }
                 }
             } else {
                 if (!empty($datas['remove_cover'])) {
                     $weblink->setCover(null);
                     if (empty($datas['link'])) {
                         $html['success_message'] = $this->_("The image has been successfully deleted");
                     }
                 }
             }
             // Sauvegarde le weblink
             $weblink->save();
             if (!empty($datas['link'])) {
                 $link_datas = $datas['link'];
                 if (empty($link_datas['url']) or !Zend_Uri::check($link_datas['url'])) {
                     throw new Exception($this->_('Please enter a valid url'));
                 }
                 // Prépare le link
                 $link = new Weblink_Model_Weblink_Link();
                 if (!empty($link_datas['link_id'])) {
                     $link->find($link_datas['link_id']);
                 }
                 $isNew = !$link->getId();
                 $link_datas['weblink_id'] = $weblink->getId();
                 // Test s'il y a un picto
                 if (!empty($link_datas['picto']) and file_exists(Core_Model_Directory::getTmpDirectory(true) . '/' . $link_datas['picto'])) {
                     $relative_path = '/pictos/';
                     $folder = Application_Model_Application::getBaseImagePath() . $relative_path;
                     $path = Application_Model_Application::getBaseImagePath() . $relative_path;
                     $file = Core_Model_Directory::getTmpDirectory(true) . '/' . $link_datas['picto'];
                     if (!is_dir($path)) {
                         mkdir($path, 0777, true);
                     }
                     if (!copy($file, $folder . $link_datas['picto'])) {
                         throw new exception($this->_("An error occurred while saving your picto. Please try againg later."));
                     } else {
                         $link_datas['picto'] = $relative_path . $link_datas['picto'];
                     }
                 }
                 // Sauvegarde le link
                 $link->addData($link_datas)->save();
                 if ($link->getIsDeleted()) {
                     $html['success_message'] = $this->_('Link has been successfully deleted');
                     $html['is_deleted'] = 1;
                 }
             }
             if ($isNew) {
                 $html['row_html'] = $this->getLayout()->addPartial('row_', 'admin_view_default', 'weblink/application/multi/edit/row.phtml')->setCurrentLink($link)->setCurrentOptionValue($option_value)->toHtml();
             }
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }