Ejemplo n.º 1
0
	public function guide_items_all() {
		$this->setDataType("list");
		$this->setActionType("modify");
		if($this->ifNotXmlMode()) return $this->doData();

		$per_page = $this->per_page;
		$guide_id = (int) getRequest('param0');

		$sel = new selector('objects');
		$sel->types('object-type')->id($guide_id);

		$maxItemsCount = (int) mainConfiguration::getInstance()->get("kernel", "max-guided-items");

		if ($maxItemsCount && $maxItemsCount <= 15 && $maxItemsCount > 0) {
			$maxItemsCount = 16;
		} elseif ($maxItemsCount <= 0) {
			$maxItemsCount = 50;
		}

		if ($textSearch = getRequest('search')) {
			foreach($textSearch as $searchString)
				$sel->where('name')->like('%' . $searchString . '%');
		}

		if (!permissionsCollection::getInstance()->isSv()) {
			$sel->where('guid')->notequals('users-users-15');
		}

		if(!is_null(getRequest('limit'))) {
			$sel->limit((15 * (int) getRequest('p')), 15);
		}

		$sel->option('return')->value('count');
		$total = $sel->length;

		if(!is_null(getRequest('allow-empty')) && $total > $maxItemsCount) {
			$data = Array(
				'empty' => Array(
					'attribute:total'  => $total,
					'attribute:result' => 'Too much items'
				)
			);
			$this->setDataRange(0, 0);
			$this->setData($data, $total);
			return $this->doData();

		} else {
			$sel->flush();
			$sel->option('return')->value('id');

			$guide_items = array();
			$tmp = array();
			$objects = umiObjectsCollection::getInstance();

			foreach($sel->result as $itemArray) {
				$itemId = $itemArray['id'];
				$item = $objects->getObject($itemId);
				if ($item instanceof umiObject) {
					$tmp[$itemId] = $item->getName();
					$guide_items[$itemId] = $item;
				}
			}

			if(!intval(regedit::getInstance()->getVal("//settings/ignore_guides_sort"))) {
				natsort($tmp);
				$guide_items = array_keys($tmp);
				unset($tmp);
			}

			$this->setDataRangeByPerPage($maxItemsCount, 0);
			$data = $this->prepareData($guide_items, "objects");
			$this->setData($data, $total);
			return $this->doData();
		}
	}
 /**
  * TODO PHPDoc
  * Enter description here ...
  * @param unknown_type $field
  * @param unknown_type $is_multiple
  * @param unknown_type $object
  * @param unknown_type $template
  */
 public function renderEditFieldRelation($field, $is_multiple, $object, $template)
 {
     if (!$field instanceof umiField) {
         return;
     }
     $controller = cmsController::getInstance();
     $objects = umiObjectsCollection::getInstance();
     $guide_items = array();
     $fieldName = $field->getName();
     if ($guide_id = $field->getGuideId()) {
         if ($controller->getCurrentMode() != "admin") {
             $guide_items = $objects->getGuidedItems($guide_id);
         } else {
             try {
                 $sel = new selector('objects');
                 $sel->option('return')->value('count');
                 $sel->types('object-type')->id($guide_id);
                 $total = $sel->length;
             } catch (selectorException $e) {
                 $total = 16;
             }
             if ($total <= 15) {
                 $sel->flush();
                 $sel->option('return')->value('id', 'name');
                 foreach ($sel->result as $item) {
                     $guide_items[$item['id']] = $item['name'];
                 }
             } else {
                 if ($object instanceof iUmiObject) {
                     $val = $object->getValue($fieldName);
                 } else {
                     $val = false;
                 }
                 if ($val && !is_array($val)) {
                     $val = array($val);
                 }
                 if (is_array($val)) {
                     foreach ($val as $item_id) {
                         $item = $objects->getObject($item_id);
                         if ($item instanceof iUmiObject) {
                             $guide_items[$item_id] = $item->getName();
                         }
                     }
                     unset($item_id, $item, $val);
                 }
             }
         }
     }
     if (sizeof($guide_items) == 0) {
         if ($object instanceof iUmiObject) {
             $val = $object->getValue($fieldName);
             if ($val && !is_array($val)) {
                 $val = array($val);
             }
             if (sizeof($val)) {
                 foreach ($val as $itemId) {
                     if ($item = selector::get('object')->id($itemId)) {
                         $guide_items[$itemId] = $item->name;
                     }
                 }
             }
         }
     }
     list($template_block, $template_block_line, $template_block_line_a, $template_mul_block, $template_mul_block_line, $template_mul_block_line_a) = def_module::loadTemplates("data/reflection/{$template}", "reflection_field_relation", "reflection_field_relation_option", "reflection_field_relation_option_a", "reflection_field_multiple_relation", "reflection_field_multiple_relation_option", "reflection_field_multiple_relation_option_a");
     $block_arr = array();
     $value = $object ? $object->getValue($fieldName) : array();
     if ($fieldName == 'publish_status' && $controller->getCurrentMode() != "admin") {
         return "";
     }
     $block_arr['attribute:name'] = $fieldName;
     $block_arr['attribute:title'] = $field->getTitle();
     $block_arr['attribute:tip'] = $field->getTip();
     $block_arr['attribute:field_id'] = $field->getId();
     if ($is_multiple) {
         $block_arr['attribute:multiple'] = "multiple";
     }
     if ($guide_id) {
         $block_arr['attribute:type-id'] = $guide_id;
         $guide = umiObjectTypesCollection::getInstance()->getType($guide_id);
         if ($guide instanceof umiObjectType) {
             if ($guide->getIsPublic()) {
                 $block_arr['attribute:public-guide'] = true;
             }
         }
     }
     $options = $is_multiple ? array() : "";
     foreach ($guide_items as $item_id => $item_name) {
         $item_object = $objects->getObject($item_id);
         if (!is_object($item_object)) {
             continue;
         }
         if ($is_multiple) {
             $selected = in_array($item_id, $value) ? " selected" : "";
         } else {
             $selected = $item_id == $value ? " selected" : "";
         }
         if ($item_object->getValue("is_hidden") && !$selected) {
             continue;
         }
         if (!$template_block_line && !def_module::isXSLTResultMode()) {
             $options .= "<option value=\"{$item_id}\"{$selected}>{$item_name}</option>\n";
         } else {
             $line_arr = array();
             $line_arr['attribute:id'] = $item_id;
             $line_arr['xlink:href'] = "uobject://" . $item_id;
             $line_arr['node:name'] = $item_name;
             if ($selected) {
                 $line_arr['attribute:selected'] = "selected";
                 $line = $is_multiple ? $template_mul_block_line_a : $template_block_line_a;
             } else {
                 $line = $is_multiple ? $template_mul_block_line : $template_block_line;
             }
             $options[] = def_module::parseTemplate($line, $line_arr, false, $item_id);
         }
     }
     if ($object) {
         $block_arr['void:object_id'] = $object->getId();
     }
     $block_arr['subnodes:values'] = $block_arr['void:options'] = $options;
     $block_arr['attribute:input_name'] = $object ? "data[" . $object->getId() . "][{$fieldName}]" . ($is_multiple ? "[]" : "") : "data[new][{$fieldName}]" . ($is_multiple ? "[]" : "");
     return def_module::parseTemplate($is_multiple ? $template_mul_block : $template_block, $block_arr);
 }