/** * This function will return paginated result. Result is an array where first element is * array of returned object and second populated pagination object that can be used for * obtaining and rendering pagination data using various helpers. * * Items and pagination array vars are indexed with 0 for items and 1 for pagination * because you can't use associative indexing with list() construct * * @access public * @param array $arguments Query argumens (@see find()) Limit and offset are ignored! * @param integer $items_per_page Number of items per page * @param integer $current_page Current page number * @return array */ function paginate($arguments = null, $items_per_page = 10, $current_page = 1) { if(isset($this) && instance_of($this, 'ObjectProperties')) { return parent::paginate($arguments, $items_per_page, $current_page); } else { return ObjectProperties::instance()->paginate($arguments, $items_per_page, $current_page); //$instance =& ObjectProperties::instance(); //return $instance->paginate($arguments, $items_per_page, $current_page); } // if } // paginate
/** * Transforms list to Array * * @return Array Returns array */ public function toArray() { $result = ObjectProperties::get($this); if (count($this->_properties) > 0) { foreach ($this->_properties as $property) { if (!empty($this->{$property})) { $result[$property] = $this->{$property}->toArray(); } } } return $result; }
function clearObjectProperties() { ObjectProperties::deleteAllByObject($this); if ($this->isSearchable()) { SearchableObjects::dropObjectPropertiesByObject($this); } }
foreach ($srrow['context'] as $context) { // Draw context if ($context['context'] != '' && $context['column_name'] != 'title' && $context['column_name'] != 'name' && $context['column_name'] != 'firstname' && $context['column_name'] != 'lastname' && $context['column_name'] != 'subject' && $context['column_name'] != 'filename') { ?> <tr style="vertical-align:middle" class="<?php echo $alt ? "searchAltRow" : 'searchRow'; ?> "> <td></td><td colspan=2 style="padding:6px;padding-top:0px"> <b><?php $colname = $context['column_name']; //Check for custom properties if (substr($colname, 0, 8) == 'property') { $property_id = trim(substr($colname, 8)); if (is_numeric($property_id)) { $prop = ObjectProperties::findById($property_id); if ($prop instanceof ObjectProperty) { echo $prop->getPropertyName(); } else { break; } } else { break; } } else { if (Localization::instance()->lang_exists('field ' . $object->getObjectManagerName() . ' ' . $context['column_name'])) { echo lang('field ' . $object->getObjectManagerName() . ' ' . $context['column_name']); } else { echo clean($context['column_name']); } }
/** * Update, delete and add new properties * * @access public * @param void * @return null */ function update_properties() { if (logged_user()->isGuest()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $this->setTemplate('add_properties'); $manager_class = array_var($_GET, 'manager'); $object_id = get_id('object_id'); $obj = Objects::findObject($object_id); if (!$obj instanceof ContentDataObject) { flash_error(lang('object dnx')); ajx_current("empty"); return; } // if if (!logged_user()->getCanManageProperties()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if $new_properties = array_var($_POST, 'new_properties'); $update_properties = array_var($_POST, 'update_properties'); $delete_properties = array_var($_POST, 'delete_properties'); if (is_array(array_var($_POST, 'new_properties')) || is_array(array_var($_POST, 'update_properties'))) { try { DB::beginWork(); //add new properties foreach ($new_properties as $prop) { $property = new ObjectProperty(); $property->setFromAttributes($prop); $property->setRelObjectId($object_id); $property->save(); } foreach ($update_properties as $prop) { $property = ObjectProperties::getProperty(array_var($prop, 'id')); //ObjectProperties::getPropertyByName($obj, array_var($prop,'name')); $property->setPropertyValue(array_var($prop, 'value')); $property->save(); } foreach ($delete_properties as $prop) { $property = ObjectProperties::getProperty(array_var($prop, 'id')); //ObjectProperties::getPropertyByName($obj, array_var($prop,'name')); $prop->delete(); } tpl_assign('properties', ObjectProperties::getAllPropertiesByObject($obj)); ApplicationLogs::createLog($obj, ApplicationLogs::ACTION_EDIT); DB::commit(); flash_success(lang('success add properties')); $this->redirectToReferer($obj->getObjectUrl()); } catch (Exception $e) { DB::rollback(); flash_error($e->getMessage()); ajx_current("empty"); } // } // if }
/** * Renders a form to set an object's custom properties. * * @param ContentDataObject $object * @return string */ function render_add_custom_properties(ContentDataObject $object) { if (!config_option('use_object_properties')) { return ''; } $genid = gen_id(); $output = ' <div id="'.$genid.'" class="og-add-custom-properties"> <table><tbody><tr> <th>' . lang('name') . '</th> <th>' . lang('value') . '</th> <th class="actions"></th> </tr></tbody></table> <a href="#" onclick="og.addObjectCustomProperty(this.parentNode, \'\', \'\', true);return false;">' . lang("add custom property") . '</a> </div> <script> var ti = 30000; og.addObjectCustomProperty = function(parent, name, value, focus) { var count = parent.getElementsByTagName("tr").length - 1; var tbody = parent.getElementsByTagName("tbody")[0]; var tr = document.createElement("tr"); var td = document.createElement("td"); td.innerHTML = \'<input class="name" type="text" name="custom_prop_names[\' + count + \']" value="\' + name + \'" tabindex=\' + ti + \'>\';; if (td.children) var input = td.children[0]; tr.appendChild(td); var td = document.createElement("td"); td.innerHTML = \'<input class="value" type="text" name="custom_prop_values[\' + count + \']" value="\' + value + \'" tabindex=\' + (ti + 1) + \'>\';; tr.appendChild(td); var td = document.createElement("td"); td.innerHTML = \'<div class="ico ico-delete" style="width:16px;height:16px;cursor:pointer" onclick="og.removeCustomProperty(this.parentNode.parentNode);return false;"> </div>\'; tr.appendChild(td); tbody.appendChild(tr); if (input && focus) input.focus(); ti += 2; } og.removeCustomProperty = function(tr) { var parent = tr.parentNode; parent.removeChild(tr); // reorder property names var row = parent.firstChild; var num = -1; // first row has no inputs while (row != null) { if (row.tagName == "TR") { var inputs = row.getElementsByTagName("INPUT"); for (var i=0; i < inputs.length; i++) { var input = inputs[i]; if (input.className == "name") { input.name = "custom_prop_names[" + num + "]"; } else { input.name = "custom_prop_values[" + num + "]"; } } num++; } row = row.nextSibling; } } </script> '; $properties = ObjectProperties::getAllPropertiesByObject($object); if (is_array($properties)) { foreach($properties as $property) { $output .= '<script>og.addObjectCustomProperty(document.getElementById("'.$genid.'"), "'.clean($property->getPropertyName()).'", "'.clean($property->getPropertyValue()).'");</script>'; } // for } // if $output .= '<script>og.addObjectCustomProperty(document.getElementById("'.$genid.'"), "", "");</script>'; return $output; }
/** * Transforms list to Array * * @return Array Returns array */ public function toArray() { $result = ObjectProperties::get($this); if (count($this->_properties) > 0) { foreach ($this->_properties as $property) { if ($this instanceof PaginationType) { $result[$property] = $this->{$property}; } else { if (!empty($this->{$property})) { if ($this->{$property} instanceof AbstractDataType || $this->{$property} instanceof AbstractListDataType) { $result[$property] = $this->{$property}->toArray(); } else { $result[$property] = $this->{$property}; } } } } } return $result; }
/** * Return manager instance * * @access protected * @param void * @return ObjectProperty */ function manager() { if(!($this->manager instanceof ObjectProperties )) $this->manager = ObjectProperties::instance(); return $this->manager; } // manager
/** * Return manager instance * * @access protected * @param void * @return ObjectProperty */ function manager() { if (!$this->manager instanceof ObjectProperties) { $this->manager = ObjectProperties::instance(); } return $this->manager; }