/**
  * Takes the page, region and field name and gets select box options for the dataselect field type
  * @param  string $regionPage Page path
  * @param  string $regionKey  The name of a region, as used in the page
  * @param  string $fieldID    The title of a field
  * @param  string $valueID    If set, the field to use for values
  * @return array             Options array with label and value keys for select field type.
  */
 public function find_data_select_options($regionPage, $regionKey, $fieldID, $valueID = false)
 {
     $sql = 'SELECT * FROM ' . $this->table . ' 
             WHERE regionPage=' . $this->db->pdb($regionPage) . '
                 AND regionKey=' . $this->db->pdb($regionKey);
     $region = $this->db->get_row($sql);
     if (PerchUtil::count($region)) {
         $Items = new PerchContent_Items();
         $items = $Items->get_for_region($region['regionID'], $region['regionLatestRev']);
         $opts = array();
         if (PerchUtil::count($items)) {
             foreach ($items as $Item) {
                 $details = PerchUtil::json_safe_decode($Item->itemJSON());
                 if (is_object($details)) {
                     $tmp = array();
                     $fieldIDs = explode(' ', $fieldID);
                     $label = array();
                     if (PerchUtil::count($fieldIDs)) {
                         foreach ($fieldIDs as $field) {
                             if ($details->{$field}) {
                                 $label[] = $details->{$field};
                             }
                         }
                     }
                     if ($label) {
                         $tmp['label'] = implode(' ', $label);
                         if ($valueID && $details->{$valueID}) {
                             $tmp['value'] = $details->{$valueID};
                         } else {
                             $tmp['value'] = $tmp['label'];
                         }
                     }
                     if (count($tmp)) {
                         $opts[] = $tmp;
                     }
                 }
             }
         }
         return $opts;
     }
 }
 private function _get_next_item_id()
 {
     $Items = new PerchContent_Items();
     return $Items->get_next_id();
 }
Exemplo n.º 3
0
<?php

$Regions = new PerchContent_Regions();
$Items = new PerchContent_Items();
$Region = false;
// Find the region
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
    $id = (int) $_GET['id'];
    $Region = $Regions->find($id);
}
// Check we have a region
if (!$Region || !is_object($Region)) {
    PerchUtil::redirect(PERCH_LOGINPATH . '/core/apps/content/');
}
// Check permissions
if (!$Region->role_may_edit($CurrentUser)) {
    PerchUtil::redirect(PERCH_LOGINPATH . '/core/apps/content/edit/denied/');
}
$Form = new PerchForm('reorder');
if ($Form->posted() && $Form->validate()) {
    $items = $Form->find_items('item_');
    if (PerchUtil::count($items)) {
        foreach ($items as $itemID => $itemOrder) {
            $Item = $Items->find_item($Region->id(), $itemID, $Region->regionLatestRev());
            if (is_object($Item)) {
                $data = array();
                $data['itemOrder'] = (int) $itemOrder;
                $Item->update($data);
            }
        }
        $Region->set_option('sortField', '');