public function Info($pa_parameters)
 {
     parent::info($pa_parameters);
     $vn_item_id = isset($pa_parameters['item_id']) ? $pa_parameters['item_id'] : null;
     $t_set_item = new ca_set_items($vn_item_id);
     $this->view->setVar('t_set', $t_set = new ca_sets($t_set_item->get('set_id')));
     if ($t_set_item->getPrimaryKey()) {
         $t_row_instance = $this->opo_datamodel->getInstanceByTableNum($t_set->get('table_num'), true);
         $t_row_instance->load($t_set_item->get('row_id'));
         $this->view->setVar('t_row_instance', $t_row_instance);
     }
     return $this->render('widget_set_item_info_html.php', true);
 }
Ejemplo n.º 2
0
 /**
  * Add item to currently loaded set
  *
  * @param int $pn_row_id The row_id to add to the set. Assumed to be a key to a record in the sets's content type's table.
  * @param array $pa_labels An array of ca_set_item label values to create. The array is keyed on locale_id; each value is an array with keys set to ca_set_item_labels fields with associated values.
  * @param int $pn_user_id user_id of user adding the item. Used to check if the user has editing access to the set. If omitted no checking of access is done.
  * @param int $pn_rank position in the set of the newly added item
  * @return int Returns item_id of newly created set item entry. The item_id is a unique identifier for the row_id in the city at the specified position (rank). It is *not* the same as the row_id.
  */
 public function addItem($pn_row_id, $pa_labels = null, $pn_user_id = null, $pn_rank = null)
 {
     if (!($vn_set_id = $this->getPrimaryKey())) {
         return null;
     }
     if ($pn_user_id && !$this->haveAccessToSet($pn_user_id, __CA_SET_EDIT_ACCESS__)) {
         return false;
     }
     $vn_table_num = $this->get('table_num');
     $o_trans = null;
     if ($this->inTransaction()) {
         $o_trans = $this->getTransaction();
     }
     // Verify existance of row before adding to set
     $t_instance = $this->getAppDatamodel()->getInstanceByTableNum($vn_table_num, true);
     if ($o_trans) {
         $t_instance->setTransaction($o_trans);
     }
     if (!$t_instance->load($pn_row_id)) {
         $this->postError(750, _t('Item does not exist'), 'ca_sets->addItem()');
         return false;
     }
     // Add it to the set
     $t_item = new ca_set_items();
     if ($o_trans) {
         $t_item->setTransaction($o_trans);
     }
     $t_item->setMode(ACCESS_WRITE);
     $t_item->set('set_id', $this->getPrimaryKey());
     $t_item->set('table_num', $vn_table_num);
     $t_item->set('row_id', $pn_row_id);
     $t_item->set('type_id', $this->get('type_id'));
     $t_item->insert();
     if (!is_null($pn_rank)) {
         $t_item->set('rank', $pn_rank);
         $t_item->update();
     }
     if ($t_item->numErrors()) {
         $this->errors = $t_item->errors;
         return false;
     }
     if (is_array($pa_labels) && sizeof($pa_labels)) {
         foreach ($pa_labels as $vn_locale_id => $va_label) {
             if (!isset($va_label['caption']) || !trim($va_label['caption'])) {
                 continue;
             }
             $t_item->addLabel($va_label, $vn_locale_id);
             if ($t_item->numErrors()) {
                 $this->errors = $t_item->errors;
                 return false;
             }
         }
     } else {
         global $g_ui_locale_id;
         if (!$g_ui_locale_id) {
             $g_ui_locale_id = 1;
         }
         $t_item->addLabel(array('caption' => _t('[BLANK]')), $g_ui_locale_id);
         if ($t_item->numErrors()) {
             $t_item->delete();
             $this->errors = $t_item->errors;
             return false;
         }
     }
     return (int) $t_item->getPrimaryKey();
 }
Ejemplo n.º 3
0
 public function RecordRepresentationSelection()
 {
     $pn_item_id = $this->request->getParameter('item_id', pInteger);
     $pn_representation_id = $this->request->getParameter('representation_id', pInteger);
     $pn_selected = $this->request->getParameter('selected', pInteger);
     $va_errors = array();
     $t_set_item = new ca_set_items($pn_item_id);
     $t_set = new ca_sets($t_set_item->get('set_id'));
     if (!$t_set->getPrimaryKey() || !$t_set->haveAccessToSet($this->request->getUserID(), __CA_SET_EDIT_ACCESS__)) {
         // TODO: proper error reporting or redirect?
         return;
     }
     if (!$t_set_item->getPrimaryKey()) {
         $va_errors[] = _t("Invalid set item");
     }
     if (!sizeof($va_errors)) {
         $t_set = new ca_sets($t_set_item->get('set_id'));
         if (!$t_set->getPrimaryKey()) {
             $va_errors[] = _t("Invalid set");
         }
         if (!$t_set->haveAccessToSet($this->request->getUserID(), __CA_SET_EDIT_ACCESS__)) {
             $va_errors[] = _t("You do not have access to this set");
         }
         if (!sizeof($va_errors)) {
             if ((bool) $pn_selected) {
                 $t_set_item->addSelectedRepresentation($pn_representation_id);
             } else {
                 $t_set_item->removeSelectedRepresentation($pn_representation_id);
             }
             $t_set_item->update();
             $va_errors = $t_set_item->getErrors();
         }
     }
     $this->view->setVar("errors", $va_errors);
     $this->view->setVar('representation_id', $pn_representation_id);
     $this->view->setVar('item_id', $pn_item_id);
     $this->render("ajax_select_representation_json.php");
 }