Exemplo n.º 1
0
 public function saveSetInfo()
 {
     if (!$this->request->isLoggedIn()) {
         $this->response->setRedirect(caNavUrl($this->request, '', 'LoginReg', 'form'));
         return;
     }
     global $g_ui_locale_id;
     // current locale_id for user
     $va_errors_edit_set = array();
     $t_set = new ca_sets();
     $pn_set_id = $this->request->getParameter('set_id', pInteger);
     $ps_name = $this->request->getParameter('name', pString);
     if (!$ps_name) {
         $va_errors_edit_set["name"] = _t("You must enter a name for your collection");
     }
     $vs_desc = $this->request->getParameter('description', pString);
     if (sizeof($va_errors_edit_set) == 0) {
         if ($t_set->load($pn_set_id) && $t_set->haveAccessToSet($this->request->getUserID(), __CA_SET_EDIT_ACCESS__)) {
             $t_set->setMode(ACCESS_WRITE);
             $t_set->set('access', $this->request->getParameter('access', pInteger));
             // edit/add description
             $va_intro_texts = $t_set->getAttributesByElement('set_intro');
             if (sizeof($va_intro_texts)) {
                 // edit existing attribute
                 $vn_attribute_id = $va_intro_texts[0]->getAttributeID();
                 $t_set->editAttribute($vn_attribute_id, 'set_intro', array('set_intro' => $vs_desc, 'locale_id' => $g_ui_locale_id));
             } else {
                 // create new attribute
                 $t_set->addAttribute(array('set_intro' => $vs_desc, 'locale_id' => $g_ui_locale_id), 'set_intro');
             }
             $t_set->update();
             if (sizeof($va_labels = caExtractValuesByUserLocale($t_set->getLabels(array($g_ui_locale_id), __CA_LABEL_TYPE_PREFERRED__)))) {
                 // edit label
                 foreach ($va_labels as $vn_set_id => $va_label) {
                     $t_set->editLabel($va_label[0]['label_id'], array('name' => $ps_name), $g_ui_locale_id);
                 }
             } else {
                 // add new label
                 $t_set->addLabel(array('name' => $ps_name), $g_ui_locale_id, null, true);
             }
         }
     }
     $this->view->setVar('errors_edit_set', $va_errors_edit_set);
     $this->index();
 }