Exemplo n.º 1
0
 /**
  * Sets order of screens in the currently loaded ui to the order of screen_ids as set in $pa_screen_ids
  *
  * @param array $pa_screen_ids A list of screen_ids in the ui, in the order in which they should be displayed in the ui
  * @param array $pa_options An optional array of options. Supported options include:
  *			NONE
  * @return array An array of errors. If the array is empty then no errors occurred
  */
 public function reorderScreens($pa_screen_ids, $pa_options = null)
 {
     if (!($vn_ui_id = $this->getPrimaryKey())) {
         return null;
     }
     $va_screen_ranks = $this->getScreenIDRanks($pa_options);
     // get current ranks
     $vn_i = 0;
     $vb_web_set_transaction = false;
     if (!$this->inTransaction()) {
         $o_trans = new Transaction($this->getDb());
         $vb_web_set_transaction = true;
     } else {
         $o_trans = $this->getTransaction();
     }
     $t_screen = new ca_editor_ui_screens();
     $t_screen->setTransaction($o_trans);
     $t_screen->setMode(ACCESS_WRITE);
     $va_errors = array();
     // delete rows not present in $pa_screen_ids
     $va_to_delete = array();
     foreach ($va_screen_ranks as $vn_screen_id => $va_rank) {
         if (!in_array($vn_screen_id, $pa_screen_ids)) {
             if ($t_screen->load(array('ui_id' => $vn_ui_id, 'screen_id' => $vn_screen_id))) {
                 $t_screen->delete(true);
             }
         }
     }
     // rewrite ranks
     foreach ($pa_screen_ids as $vn_rank => $vn_screen_id) {
         if (isset($va_screen_ranks[$vn_screen_id]) && $t_screen->load(array('ui_id' => $vn_ui_id, 'screen_id' => $vn_screen_id))) {
             if ($va_screen_ranks[$vn_screen_id] != $vn_rank) {
                 $t_screen->set('rank', $vn_rank);
                 $t_screen->update();
                 if ($t_screen->numErrors()) {
                     $va_errors[$vn_screen_id] = _t('Could not reorder screen %1: %2', $vn_screen_id, join('; ', $t_screen->getErrors()));
                 }
             }
         } else {
             // add screen to UI
             //	$this->addItem($vn_screen_id, null, $vn_user_id, $vn_rank);
         }
     }
     if (sizeof($va_errors)) {
         if ($vb_web_set_transaction) {
             $o_trans->rollback();
         }
     } else {
         if ($vb_web_set_transaction) {
             $o_trans->commit();
         }
     }
     return $va_errors;
 }