Esempio n. 1
0
 public function saveAjaxAction(\Difra\Param\AjaxString $name, \Difra\Param\AjaxHTML $description, \Difra\Param\AjaxString $release = null, \Difra\Param\AjaxString $link = null, \Difra\Param\AjaxString $link_caption = null, \Difra\Param\AjaxString $software = null, \Difra\Param\AjaxInt $id = null, \Difra\Param\AjaxData $roles = null, \Difra\Param\AjaxFiles $image = null)
 {
     if (is_null($id) && !\Difra\Plugins\Portfolio::checkURI($name->val())) {
         $this->ajax->invalid('name');
         $this->ajax->status('name', \Difra\Locales::getInstance()->getXPath('portfolio/adm/notify/dupName'), 'problem');
         return;
     }
     if ($id) {
         $entry = \Difra\Unify::getObj('PortfolioEntry', (string) $id);
     } else {
         $entry = \Difra\Unify::createObj('PortfolioEntry');
     }
     $entry->name = $name;
     if (!is_null($release)) {
         $release = strtotime($release->val() . ' 00:00:00');
         $release = date('Y-m-d', $release);
     }
     $entry->description = $description;
     $entry->release = $release;
     $entry->link = $link;
     $entry->link_caption = $link_caption;
     $entry->software = $software;
     $entry->uri = \Difra\Locales::getInstance()->makeLink($name->val());
     $sortedAuthors = [];
     if (!is_null($roles)) {
         $authors = $roles->val();
         if (!empty($authors)) {
             foreach ($authors as $line) {
                 if (empty($line)) {
                     continue;
                 }
                 $role = false;
                 $contributors = [];
                 foreach ($line as $k => $v) {
                     if ($k === 'role') {
                         $role = $v;
                     } else {
                         $contributors[] = $v;
                     }
                 }
                 if ($role and !empty($contributors)) {
                     $sortedAuthors[] = ['role' => $role, 'contibutors' => $contributors];
                 }
             }
         }
     }
     $entry->authors = $sortedAuthors;
     try {
         $entry->save();
     } catch (\Difra\Exception $x) {
         $x->notify();
         $this->ajax->notify($x->getMessage());
         return;
     }
     if (!is_null($image)) {
         if ($id) {
             $eId = $id->val();
         } else {
             $eId = $entry->getPrimaryValue();
         }
         try {
             \Difra\Plugins\Portfolio::saveImages($eId, $image);
         } catch (\Difra\Exception $x) {
             $x->notify();
             $this->ajax->notify($x->getMessage());
             return;
         }
     }
     $Locales = \Difra\Locales::getInstance();
     if ($id) {
         $notify = $Locales->getXPath('portfolio/adm/notify/edited');
     } else {
         $notify = $Locales->getXPath('portfolio/adm/notify/added');
     }
     $this->ajax->notify($notify);
     $this->ajax->redirect('/adm/content/portfolio/');
 }