public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { $env = new self(); $found_env = $env->find(); $nb = count($found_env); return self::createTabEntry(self::getTypeName($nb), $nb); }
static function getHistory($tickets_id, $full_history = false) { global $CFG_GLPI; $filter_groups_id = array(); if ($_SESSION['plugins']['escalade']['config']['use_filter_assign_group']) { $groups_groups = new PluginEscaladeGroup_Group(); $filter_groups_id = $groups_groups->getGroups($tickets_id); $use_filter_assign_group = true; } else { $use_filter_assign_group = false; } $plugin_dir = $full_history ? ".." : "../plugins/escalade"; //get all line for this ticket $group = new Group(); $history = new self(); $found = $history->find("tickets_id = {$tickets_id}", "date_mod DESC"); $nb_histories = count($found); //remove first line (current assign) $first_group = array_shift($found); if ($full_history) { //show 1st group echo "<div class='escalade_active'>"; echo " <img src='" . $CFG_GLPI['root_doc'] . "/pics/group.png' /> "; if ($group->getFromDB($first_group['groups_id'])) { echo $group->getLink(true); } echo "</div>"; } echo "<div class='escalade'>"; //parse all lines $i = 0; foreach ($found as $key => $hline) { echo "<div class='escalade_history'>"; if (!$use_filter_assign_group || isset($filter_groups_id[$hline['groups_id']])) { //up link and image echo "<a href='{$plugin_dir}/front/climb_group.php?tickets_id=" . $tickets_id . "&groups_id=" . $hline['groups_id']; if ($full_history) { echo "&full_history=true"; } echo "' title='" . __("Reassign the ticket to group", "escalade") . "' class='up_a'></a>"; } else { echo " "; } //group link echo " <img src='" . $CFG_GLPI['root_doc'] . "/pics/group.png' /> "; if ($group->getFromDB($hline['groups_id'])) { echo self::showGroupLink($group, $full_history); } echo "</div>"; $i++; if ($i == self::HISTORY_LIMIT && !$full_history) { break; } } //In case there are more than 10 group changes, a popup can display historical if ($nb_histories - 1 > self::HISTORY_LIMIT && !$full_history) { echo "<a href='#' onclick='var w=window.open(\"" . $plugin_dir . "/front/popup_histories.php?tickets_id=" . $tickets_id . "\" ,\"\", \"height=500, width=250, top=100, left=100, scrollbars=yes\" ); " . "w.focus();' title='" . __("View full history", "escalade") . "'>...</a>"; } echo "</div>"; }
public function save() { $value_changed = $this->getValue() != $this->getOrigValue(); if (stripos($this->getValue(), "image/png;base64") !== false) { $data = substr($this->getValue(), strpos($this->getValue(), ",") + 1); $data = str_replace(' ', '+', $data); $data = base64_decode($data); $ext = $this->getCode() == "favicon" ? ".ico" : ".png"; $filename = $this->getCode() . $ext; $filepath = Core_Model_Directory::getBasePathTo("images/default"); if (!is_dir($filepath)) { mkdir($filepath, 0777, true); } if (!is_writable($filepath)) { throw new Exception($this->_("The folder /images/default is not writable.")); } file_put_contents("{$filepath}/{$filename}", $data); $this->setValue("/images/default/{$this->getCode()}.{$ext}"); } parent::save(); if ($this->getCode() == "system_timezone" && $value_changed) { $config = new self(); $config->find("system_territory", "code"); $value = $this->getValue(); $territories = Zend_Registry::get("Zend_Locale")->getTranslationList('TerritoryToTimezone'); $territory = $value && !empty($territories[$value]) ? $territories[$value] : null; $data = array("code" => "system_territory", "value" => $territory); $config->addData($data)->save(); } }
static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { return; $profile = new Profile(); $found_profiles = $profile->find("`interface` = 'central'"); $tab_profile = new self(); $found_tab_profiles = $tab_profile->find("`plugin_custom_tabs_id` = " . $item->getID()); echo "<form method='POST' action='tabprofile.form.php' />"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='4'>" . __("Visibility") . "</th></tr>"; $odd = 0; foreach ($found_profiles as $profiles_id => $profile_fields) { if ($odd % 2 === 0) { echo "<tr>"; } echo "<td>" . $profile_fields['name'] . "</td>"; echo "<td>"; Dropdown::showYesNo("tab_profile[{$profiles_id}]", 0); echo "</td>"; if ($odd % 2 === 1) { echo "</tr>"; } $odd++; } if ($odd % 2 === 0) { echo "</tr>"; } echo "<tr><td colspan='4'><div class='center'>"; echo "<input type='submit' name='update' value=\"" . _sx('button', 'Post') . "\" class='submit'>"; echo "</div></td></tr>"; echo "</table>"; Html::closeForm(); return true; }
public static function getAreaByStateId($stateId) { $stateModel = new self(); $state = $stateModel->find($stateId); if ($state) { return self::area($state->name); } return 'west'; }
public static function getAndroidSenderId() { if (is_null(self::$_android_sender_id)) { $certificat = new self(); $certificat->find('android_sender_id', 'type'); self::$_android_sender_id = $certificat->getPath(); } return self::$_android_sender_id; }
static function countForLock(CommonGLPI $item) { $pfLock = new self(); $a_data = current($pfLock->find("`tablename`='" . $item->getTable() . "'\n AND `items_id`='" . $item->getID() . "'", "", 1)); if (count($a_data) == '0') { return 0; } else { return count(importArrayFromDB($a_data['tablefields'])); } }
static function getTag_items($id_glpi_obj, $itemtype) { $IDs = array(); //init $tagitems = new self(); foreach ($tagitems->find("itemtype = '{$itemtype}' AND items_id = {$id_glpi_obj}") as $tagitem) { $IDs[] = $tagitem["plugin_tag_tags_id"]; } return $IDs; }
static function updateProfile($input) { $fields_profile = new self(); foreach ($input['rights'] as $profiles_id => $right) { $found = $fields_profile->find("`profiles_id` = '{$profiles_id}'\n AND `plugin_fields_containers_id` = '" . $input['plugin_fields_containers_id'] . "'"); $first_found = array_shift($found); $fields_profile->update(array('id' => $first_found['id'], 'profiles_id' => $profiles_id, 'plugin_fields_containers_id' => $input['plugin_fields_containers_id'], 'right' => $right)); } return true; }
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { switch ($item->getType()) { case "PluginFormcreatorForm": $env = new self(); $found_env = $env->find('plugin_formcreator_forms_id = ' . $item->getID()); $nb = count($found_env); return self::createTabEntry(self::getTypeName($nb), $nb); } return ''; }
/** * Return the DAO object containing to the default row of * civicrm_mail_settings and cache it for further calls * * @return object DAO with the default mail settings set */ static function &defaultDAO() { static $dao = NULL; if (!$dao) { $dao = new self(); $dao->is_default = 1; $dao->domain_id = CRM_Core_Config::domainID(); $dao->find(TRUE); } return $dao; }
static function cleanup($profile_list) { $subs = new self(); $subs->profile_tag_id = $profile_list->id; $subs->find(); while ($subs->fetch()) { $profile = Profile::getKV('id', $subs->profile_id); Event::handle('StartUnsubscribePeopletag', array($profile_list, $profile)); // Delete anyway $subs->delete(); Event::handle('StartUnsubscribePeopletag', array($profile_list, $profile)); } }
/** * Return the DAO object containing to the default row of * civicrm_mail_settings and cache it for further calls * * @param bool $reset * * @return CRM_Core_BAO_MailSettings * DAO with the default mail settings set */ public static function defaultDAO($reset = FALSE) { static $mailSettings = array(); $domainID = CRM_Core_Config::domainID(); if (empty($mailSettings[$domainID]) || $reset) { $dao = new self(); $dao->is_default = 1; $dao->domain_id = $domainID; $dao->find(TRUE); $mailSettings[$domainID] = $dao; } return $mailSettings[$domainID]; }
/** * Return the name of the tab for item including forms like the config page * * @param CommonGLPI $item Instance of a CommonGLPI Item (The Config Item) * @param integer $withtemplate * * @return String Name to be displayed */ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { switch ($item->getType()) { case "PluginFormcreatorForm": $number = 0; $section = new PluginFormcreatorSection(); $found = $section->find('plugin_formcreator_forms_id = ' . $item->getID()); $tab_section = array(); foreach ($found as $section_item) { $tab_section[] = $section_item['id']; } if (!empty($tab_section)) { $object = new self(); $found = $object->find('plugin_formcreator_sections_id IN (' . implode(', ', $tab_section) . ')'); $number = count($found); } return self::createTabEntry(self::getTypeName($number), $number); } return ''; }
/** * Based on vacancy ID and/or given permission return list of permission * that the logged in user have or return TRUE/FALSE if the loggedin user * has permission in the given permission list $checkPermissions respectively * * @param int $vacancyID vacancy ID to retrieve its permission for loggedin user * @param array $checkPermissions list of permission to check if loggedin user has any of the permission for given vacancy * whose id = $vacancyID * * @return boolean|array * @access public * @static */ public static function checkVacancyPermission($vacancyID, $checkPermissions = array(), $defaultPermissions = array()) { $session = CRM_Core_Session::singleton(); $userID = $session->get('userID'); $vacancyPermissions = array(); $dao = new self(); $dao->vacancy_id = $vacancyID; $dao->contact_id = $userID; $dao->find(); if (CRM_Core_Permission::check('administer CiviCRM')) { if (count($checkPermissions) && in_array('administer CiviCRM', $checkPermissions)) { return TRUE; } else { $vacancyPermissions[] = 'administer CiviCRM'; } } if (empty($defaultPermissions)) { $defaultPermissions[] = $checkPermissions; } if (count($defaultPermissions) && CRM_Core_Permission::check($defaultPermissions)) { return TRUE; } while ($dao->fetch()) { if (count($checkPermissions)) { if (in_array($dao->permission, $checkPermissions)) { return TRUE; } } else { $vacancyPermissions[] = $dao->permission; } } if (count($checkPermissions)) { return FALSE; } return $vacancyPermissions; }
/** * @return OpenSKOS_Db_Table_Row_User */ public static function fromIdentity() { if (!Zend_Auth::getInstance()->hasIdentity()) { return; } $model = new self(); return $model->find(Zend_Auth::getInstance()->getIdentity()->id)->current(); }
static function displayList(PluginFusioninventoryDeployOrder $order, $datas, $rand) { global $CFG_GLPI; $pfDeployPackage = new PluginFusioninventoryDeployPackage(); $pfDeployPackage->getFromDB($order->fields['plugin_fusioninventory_deploypackages_id']); $o_file = new self(); // compute short shas to find the corresponding entries in database $short_shas = array(); foreach ($datas['jobs']['associatedFiles'] as $sha512) { $short_shas[] = "'" . substr($sha512, 0, 6) . "'"; } // find corresponding file entries $files = $o_file->find("shortsha512 IN (" . implode(",", $short_shas) . ")"); // do a quick mapping between database id and short shas $files_mapping = array(); foreach ($files as $f) { $files_mapping[$f['shortsha512']] = $f['id']; } echo "<table class='tab_cadrehov package_item_list' id='table_file_{$rand}'>"; $i = 0; foreach ($datas['jobs']['associatedFiles'] as $sha512) { $short_sha = substr($sha512, 0, 6); $fileregistry_error = 0; // check if the files is registered in database if (!array_key_exists($short_sha, $files_mapping)) { $fileregistry_error |= self::REGISTRY_NO_DB_ENTRY; } if (!$o_file->checkPresenceManifest($sha512)) { $fileregistry_error |= self::REGISTRY_NO_MANIFEST; } // get database entries if (!$fileregistry_error) { $file_id = $files_mapping[$short_sha]; // get file's name $file_name = $files[$file_id]['name']; // get file's size $file_size = $files[$file_id]['filesize']; //mimetype icon if (isset($files[$file_id]['mimetype'])) { $file_mimetype = str_replace('/', '__', $files[$file_id]['mimetype']); } else { $file_mimetype = NULL; } } else { // get file's name from what has been saved in json $file_name = $datas['associatedFiles'][$sha512]['name']; $file_size = NULL; $file_mimetype = NULL; } $file_uncompress = $datas['associatedFiles'][$sha512]['uncompress']; $file_p2p = $datas['associatedFiles'][$sha512]['p2p']; $file_p2p_retention_duration = $datas['associatedFiles'][$sha512]['p2p-retention-duration']; // start new line $pics_path = $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/"; echo Search::showNewLine(Search::HTML_OUTPUT, $i % 2); if ($pfDeployPackage->can($pfDeployPackage->getID(), UPDATE)) { echo "<td class='control'>"; Html::showCheckbox(array('name' => 'file_entries[]', 'value' => 0)); echo "</td>"; } echo "<td class='filename'>"; if (!empty($file_mimetype) && file_exists(GLPI_ROOT . "/plugins/fusioninventory/pics/ext/extensions/{$file_mimetype}.png")) { echo "<img src='" . $pics_path . "ext/extensions/{$file_mimetype}.png' />"; } else { echo "<img src='" . $pics_path . "ext/extensions/documents.png' />"; } //filename echo " " . "<a class='edit' " . " onclick=\"edit_subtype(" . " 'file', {$order->fields['id']}, {$rand}, this " . " )\"" . ">{$file_name}</a>"; //p2p icon if (isset($file_p2p) && $file_p2p != 0) { echo "<a title='" . __('p2p', 'fusioninventory') . ", " . __("retention", 'fusioninventory') . " : " . $file_p2p_retention_duration . " " . __("days", 'fusioninventory') . "' class='more'>"; echo "<img src='" . $pics_path . "p2p.png' />"; echo "<sup>" . $file_p2p_retention_duration . "</sup>"; echo "</a>"; } //uncompress icon if (isset($file_uncompress) && $file_uncompress != 0) { echo "<a title='" . __('uncompress', 'fusioninventory') . "' class='more'><img src='" . $pics_path . "uncompress.png' /></a>"; } //sha fingerprint $sha_status = "good"; if ($fileregistry_error != 0) { $sha_status = "bad"; } echo "<div class='fingerprint'>"; echo "<div class='fingerprint_" . $sha_status . "'>" . $sha512; if ($fileregistry_error & self::REGISTRY_NO_DB_ENTRY) { echo "<div class='fingerprint_badmsg'>" . __("This file is not correctly registered in database.") . "<br/>" . __("You can fix it by uploading or selecting the good one."); echo "</div>"; } if ($fileregistry_error & self::REGISTRY_NO_MANIFEST) { echo "<div class='fingerprint_badmsg'>" . __("This file doesn't have any manifest file associated.") . "<br/>" . __("You must upload the file."); echo "</div>"; } echo "</div>"; echo "</div>"; //filesize if (!$fileregistry_error) { echo "<div class='size'>"; echo __('Size') . ": " . self::processFilesize($file_size); echo "</div>"; } echo "</td>"; if ($pfDeployPackage->can($pfDeployPackage->getID(), UPDATE)) { echo "<td class='rowhandler control' title='" . __('drag', 'fusioninventory') . "'><div class='drag row'></div></td>"; } $i++; } if ($pfDeployPackage->can($pfDeployPackage->getID(), UPDATE)) { echo "<tr><th>"; Html::checkAllAsCheckbox("filesList{$rand}", mt_rand()); echo "</th><th colspan='3' class='mark'></th></tr>"; } echo "</table>"; if ($pfDeployPackage->can($pfDeployPackage->getID(), UPDATE)) { echo " <img src='" . $CFG_GLPI["root_doc"] . "/pics/arrow-left.png' alt=''>"; echo "<input type='submit' name='delete' value=\"" . __('Delete', 'fusioninventory') . "\" class='submit'>"; } }
static function getSectionName($section_ID) { $section = new self(); $listSection = $section->find("id = '{$section_ID}'"); foreach ($listSection as $section) { $sectionName = $section['name']; } return $sectionName; }
/** * Iterates over each result of a query, calling a callback for each one. The * items are processed in an unspecified order. The query may not have any * sort order, and may not use limit or skip. * * @param callable $callback Callback that will be called with each result * of the query. * @param bool $useMasterKey * @param int $batchSize * * @throws \Exception If query has sort, skip, or limit. */ public function each($callback, $useMasterKey = false, $batchSize = 100) { if ($this->orderBy || $this->skip || $this->limit >= 0) { throw new Exception('Cannot iterate on a query with sort, skip, or limit.'); } $query = new self($this->className); $query->where = $this->where; $query->includes = $this->includes; $query->limit = $batchSize; $query->ascending('objectId'); $finished = false; while (!$finished) { $results = $query->find($useMasterKey); $length = count($results); for ($i = 0; $i < $length; $i++) { $callback($results[$i]); } if ($length == $query->limit) { $query->greaterThan('objectId', $results[$length - 1]->getObjectId()); } else { $finished = true; } } }
static function getSelectTitle($language) { $text = ''; $title = new self(); $requete = $title->find("language='" . $language . "'"); foreach ($requete as $value) { $text = $value["name"]; } return self::bbCode($text); }
static function tagDropdownMultiple($options = array()) { $itemtype = self::getItemtype($_REQUEST['itemtype'], $_REQUEST['id']); $obj = new $itemtype(); // Object must be an instance of CommonDBTM (or inherint of this) if (!$obj instanceof CommonDBTM) { return; } $obj->getFromDB($_REQUEST['id']); $sel_attr = $obj->canUpdateItem() ? '' : ' disabled '; echo "<select data-placeholder='" . __('Choose tags...', 'tag') . self::MNBSP . "' name='_plugin_tag_tag_values[]'\n id='tag_select' multiple class='chosen-select-no-results' " . $sel_attr . " style='width:80%;' >"; $selected_id = array(); $tag_item = new PluginTagTagItem(); foreach ($tag_item->find('items_id=' . $_REQUEST['id'] . ' AND itemtype="' . $itemtype . '"') as $found_item) { $selected_id[] = $found_item['plugin_tag_tags_id']; } // Restrict tag by entity if current object has entity $where = "1 "; if (isset($obj->fields['entities_id'])) { $field = $obj->getType() == 'Entity' ? 'id' : 'entities_id'; $where .= getEntitiesRestrictRequest("AND", '', '', $obj->fields[$field], true); } $tag = new self(); $items = $tag->find($where, 'name'); foreach ($items as $item) { $param = in_array($item['id'], $selected_id) ? ' selected ' : ''; $param .= 'data-color-option="' . $item['color'] . '"'; if (!empty($item['type_menu'])) { // Allowed types foreach (json_decode($item['type_menu'], true) as $subtype) { if (strtolower($subtype) == $itemtype) { echo '<option value="' . $item['id'] . '" ' . $param . '>' . $item['name'] . '</option>'; break; } } } else { echo '<option value="' . $item['id'] . '" ' . $param . '>' . $item['name'] . '</option>'; } } echo "</select>"; if (self::canCreate()) { $rand = mt_rand(); /* echo "<script type='text/javascript'>\n window.updateTagSelectResults_".$rand." = function () { } </script>"; */ // Show '+' button : self::showMoreButton($rand); } }
/** * Check is the given notation registered in the database. * * @param string $notation * @return bool */ public static function isRegistered($notation) { $model = new self(); $check = $model->find($notation); return $check->count() != 0; }
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { switch ($item->getType()) { case "PluginFormcreatorConfig": $object = new self(); $found = $object->find(); $number = count($found); return self::createTabEntry(self::getTypeName($number), $number); break; case "PluginFormcreatorForm": return __('Preview'); break; } return ''; }
public static function get_params($group, $subgroup, $object = '') { $params = new self(); $params->group = self::$_params['group'] = $group; $params->subgroup = self::$_params['subgroup'] = $subgroup; $params->object = self::$_params['object'] = $object; if ($params->find()) { self::$_params['notdefault'] = 1; self::$_params += json_decode($params->data, true); } return self::$_params; }
function prepareInputForAdd($input) { $cat = new self(); $found_cat = $cat->find("itilcategories_id = " . $this->input["itilcategories_id"]); if (count($found_cat) > 0) { Session::addMessageAfterRedirect(__("A link with this category already exists", "itilcategorygroups")); return false; } return $this->prepareInputForUpdate($input); }
public function __call($method, $args) { if (empty($this->_datas['foreignFields'])) { $this->_datas['foreignFields'] = array(); } if (!Arrays::is($this->_datas['foreignFields'])) { $this->_datas['foreignFields'] = array($this->_datas['foreignFields']); } if (substr($method, 0, 3) == 'get') { $vars = array_values($this->fields()); $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3))); $var = Inflector::lower($uncamelizeMethod); if (Arrays::in($var, $vars) || ake($var, $this->_datas['foreignFields']) || true === $this->hasForeignRelation($var)) { if (ake($var, $this->_datas['foreignFields']) || true === $this->hasForeignRelation($var)) { if (ake($var, $this->_datas['foreignFields']) && 'true' != $this->_datas['foreignFields'][$var]) { return $this->_datas['foreignFields'][$var]; } $var = true === $this->hasForeignRelation($var) ? $this->fkFieldName($var) : $var; $rs = $this->_datas['configModel']['relationship'][$var]; $field = $rs['fieldName']; $classModel = $this->_datas['classModel']; $obj = new $classModel(); if (Arrays::inArray($field, $this->_datas['keys'])) { $modelField = $rs['foreignTable']; if (isset($this->_datas['configModel']['relationship']) && ake($field, $this->_datas['configModel']['relationship'])) { $m = $this->_datas['configModel']['relationship'][$field]; if (ake("entity", $rs)) { $entity = $rs['entity']; } else { $entity = $obj->_entity; } if (null !== $m['type']) { switch ($m['type']) { case 'manyToOne': case 'oneToOne': $nObj = new self($entity, $modelField); if (ake("relationshipKeys", $rs)) { $field = $rs['relationshipKeys']; } if (!is_null($this->{$field})) { if (false === $this->_cache) { $result = $nObj->find($this->{$field}); } else { $result = $nObj->cache($this->_cache)->find($this->{$field}); $this->_cache = false; } $this->_datas['foreignFields'][$var] = $result; return $result; } break; case 'manyToMany': case 'oneToMany': $nObj = new self($entity, $modelField); $getter = $this->pk(); $fk = ake("relationshipKeys", $rs) ? $rs['relationshipKeys'][$field] : $rs['foreignKey']; if (false === $this->_cache) { $result = $nObj->where($nObj->_dbName . '.' . $nObj->_tableName . "." . $fk . " = " . $nObj->quote($this->{$getter}))->select(); } else { $result = $nObj->cache($this->_cache)->where($nObj->_dbName . '.' . $nObj->_tableName . "." . $fk . " = " . $nObj->quote($this->{$getter}))->select(); $this->_cache = false; } $this->_datas['foreignFields'][$var] = $result; return $result; break; } } } } } if (isset($this->{$var}) || is_null($this->{$var})) { return $this->{$var}; } else { throw new Exception("Unknown field {$var} in " . get_class($this) . " class."); } } return null; } elseif (substr($method, 0, 3) == 'set') { $vars = array_values($this->fields()); $value = $args[0]; $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3))); $var = Inflector::lower($uncamelizeMethod); if (Arrays::in($var, $vars) || ake($var, $this->_datas['foreignFields']) || true === $this->hasForeignRelation($var)) { if (ake($var, $this->_datas['foreignFields']) || true === $this->hasForeignRelation($var)) { $var = true === $this->hasForeignRelation($var) ? $this->fkFieldName($var) : $var; $this->_datas['foreignFields'][$var] = $value; $rs = $this->_datas['configModel']['relationship'][$var]; $setField = $rs['fieldName']; $getter = $rs['foreignKey']; if (Arrays::in($setField, $vars) && isset($value->{$getter})) { $this->{$setField} = $value->{$getter}; return $this; } else { return $this; } } else { $this->{$var} = $value; return $this; } } else { throw new Exception("Unknown field {$var} in " . get_class($this) . " class."); } } elseif (substr($method, 0, 3) == 'min') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3))); $var = Inflector::lower($uncamelizeMethod); if ($var == 'id') { $var = $this->pk(); } $vars = array_values($this->fields()); if (Arrays::in($var, $vars)) { return $this->min($var); } } elseif (substr($method, 0, 3) == 'max') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3))); $var = Inflector::lower($uncamelizeMethod); if ($var == 'id') { $var = $this->pk(); } $vars = array_values($this->fields()); if (Arrays::in($var, $vars)) { return $this->max($var); } } elseif (substr($method, 0, 3) == 'avg') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3))); $var = Inflector::lower($uncamelizeMethod); if ($var == 'id') { $var = $this->pk(); } $vars = array_values($this->fields()); if (Arrays::in($var, $vars)) { return $this->avg($var); } } elseif (substr($method, 0, 3) == 'sum') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3))); $var = Inflector::lower($uncamelizeMethod); if ($var == 'id') { $var = $this->pk(); } $vars = array_values($this->fields()); if (Arrays::inArray($var, $vars)) { return $this->sum($var); } } elseif (substr($method, 0, 5) == 'count') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 5))); $var = Inflector::lower($uncamelizeMethod); if ($var == 'id') { $var = $this->pk(); } $vars = array_values($this->fields()); if (Arrays::inArray($var, $vars)) { return $this->count($var); } } elseif (substr($method, 0, 6) == 'findBy') { $vars = array_values($this->fields()); $value = $args[0]; $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 6))); $var = Inflector::lower($uncamelizeMethod); $var = true === $this->hasForeignRelation($var) ? $this->fkFieldName($var) : $var; $rs = $this->_datas['configModel']['relationship'][$var]; $this->_datas['foreignFields'][$var] = $value; if (is_object($value) && null !== $this->_datas['configModel']['relationship'][$var]) { switch ($this->_datas['configModel']['relationship'][$var]) { case 'manyToOne': case 'oneToOne': $field = $rs['fieldName']; $q = $this->_dbName . '.' . $this->_tableName . "." . $field . " = " . $this->quote($value->{$field}); if (false === $this->_cache) { return $this->where($q)->select(); } else { return $this->cache($this->_cache)->where($q)->select(); $this->_cache = false; } case 'oneToMany': case 'manyToMany': $field = $rs['fieldName']; $pk = $this->pk(); $pkValue = $value->{$pk}; $q = $this->_dbName . '.' . $this->_tableName . "." . $pk . " = " . $this->quote($pkValue); if (false === $this->_cache) { return $this->where($q)->select(); } else { return $this->cache($this->_cache)->where($q)->select(); $this->_cache = false; } } } else { if (Arrays::in($var, $vars) || $var == 'id') { if ($var != 'id') { return $this->findBy($var, $value); } else { return $this->find($value); } } else { throw new Exception("Unknown field {$var} in " . get_class($this) . " class."); } } } elseif (substr($method, 0, 5) == 'where' && strlen($method) > 5) { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 5))); $var = Inflector::lower($uncamelizeMethod); if ($var == 'id') { $var = $this->pk(); } $var = $this->_dbName . '.' . $this->_tableName . '.' . $var; $condition = $args[0]; $operator = isset($args[1]) ? $args[1] : 'AND'; return $this->where("{$var} {$condition}", $operator); } elseif (substr($method, 0, 7) == 'groupBy' && strlen($method) > 7) { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 7))); $var = Inflector::lower($uncamelizeMethod); if ($var == 'id') { $var = $this->pk(); } return $this->groupBy($var); } elseif (substr($method, 0, 7) == 'orderBy') { $direction = count($args) ? $args[0] : 'ASC'; $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 7))); $var = Inflector::lower($uncamelizeMethod); return $this->order($var, $direction); } elseif (substr($method, 0, 9) == 'findOneBy') { $vars = array_values($this->fields()); $value = $args[0]; $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 9))); $var = Inflector::lower($uncamelizeMethod); if (Arrays::inArray($var, $vars) || $var == 'id') { if ($var != 'id') { return $this->findBy($var, $value, true); } else { return $this->find($value); } } else { throw new Exception("Unknown field {$var} in " . get_class($this) . " class."); } } else { $vars = array_values($this->fields()); $uncamelizeMethod = Inflector::uncamelize(lcfirst($method)); $var = Inflector::lower($uncamelizeMethod); $var = true === $this->hasForeignRelation($var) ? $this->fkFieldName($var) : $var; $rs = $this->_datas['configModel']['relationship'][$var]; $this->_datas['foreignFields'][$var] = $value; if (Arrays::in($var, $vars) || ake($var, $this->_datas['foreignFields']) || true === $this->hasForeignRelation($var)) { if (ake($var, $this->_datas['foreignFields'])) { return $this->_datas['foreignFields'][$var]; } if (isset($this->{$var})) { return $this->{$var}; } else { if (!method_exists($this, $method)) { $this->{$method} = $args[0]; } } } } }
public function order($fieldOrder = 'date_create', $orderDirection = 'ASC', $results = array()) { $res = count($results) ? $results : $this->results; $fields = $this->fields; $fields['id'] = array(); $fields['date_create'] = array(); if (!Arrays::is($fieldOrder)) { if (null !== $fieldOrder && !Arrays::exists($fieldOrder, $fields)) { $fields[$fieldOrder] = array(); } } else { foreach ($fields as $tmpField => $info) { if (null !== $tmpField && !Arrays::exists($tmpField, $fields)) { $fields[$tmpField] = array(); } } } $sort = array(); foreach ($res as $id) { $objectCreated = $this->row($id); foreach ($fields as $key => $infos) { $type = Arrays::exists('type', $fields[$key]) ? $fields[$key]['type'] : null; if ('data' == $type) { list($dummy, $foreignTable, $foreignFieldKey) = $fields[$key]['contentList']; $foreignFields = Arrays::exists($foreignTable, Data::$_fields) ? Data::$_fields[$foreignTable] : Data::noConfigFields($foreignTable); $foreignStorage = new self($foreignTable); $foreignRow = $foreignStorage->find($objectCreated->{$key}); $foreignFieldKeys = explode(',', $foreignFieldKey); $value = ''; for ($i = 0; $i < count($foreignFieldKey); $i++) { $tmpKey = $foreignFieldKey[$i]; $value .= $foreignRow->{$tmpKey} . ' '; } $value = substr($value, 0, -1); } else { $value = isset($objectCreated->{$key}) ? $objectCreated->{$key} : null; } $sort[$key][] = $value; } } $asort = array(); foreach ($sort as $key => $rows) { for ($i = 0; $i < count($rows); $i++) { if (empty(${$key}) || is_string(${$key})) { ${$key} = array(); } $asort[$i][$key] = $rows[$i]; array_push(${$key}, $rows[$i]); } } if (Arrays::is($fieldOrder) && !Arrays::is($orderDirection)) { $t = array(); foreach ($fieldOrder as $tmpField) { array_push($t, $orderDirection); } $orderDirection = $t; } if (Arrays::is($fieldOrder) && Arrays::is($orderDirection)) { if (count($orderDirection) < count($fieldOrder)) { throw new Exception('You must provide the same arguments number of fields sorting and directions sorting.'); } if (count($fieldOrder) == 1) { $fieldOrder = Arrays::first($fieldOrder); if ('ASC' == Inflector::upper(Arrays::first($orderDirection))) { array_multisort(${$fieldOrder}, SORT_ASC, $asort); } else { array_multisort(${$fieldOrder}, SORT_DESC, $asort); } } elseif (count($fieldOrder) > 1) { $params = array(); foreach ($fieldOrder as $k => $tmpField) { $tmpSort = isset($orderDirection[$k]) ? $orderDirection[$k] : 'ASC'; $params[] = ${$tmpField}; $params[] = 'ASC' == $tmpSort ? SORT_ASC : SORT_DESC; } $params[] = $asort; call_user_func_array('array_multisort', $params); } } else { if ('ASC' == Inflector::upper($orderDirection)) { array_multisort(${$fieldOrder}, SORT_ASC, $asort); } else { array_multisort(${$fieldOrder}, SORT_DESC, $asort); } } $collection = array(); foreach ($asort as $key => $row) { $tmpId = $row['id']; array_push($collection, $tmpId); } $this->results = $collection; return $this; }
static function getSingle() { $style = new self(); $tmp = $style->find(); $tmp = array_shift($tmp); if (!empty($tmp)) { return $tmp['id']; } return -1; }
/** * Print the HTML array for SLTs linked to a SLA * * @param SLA $sla * @return boolean */ static function showForSla(SLA $sla) { global $CFG_GLPI; $instID = $sla->fields['id']; $slt = new self(); $calendar = new Calendar(); if (!$sla->can($instID, READ)) { return false; } $canedit = $sla->canEdit($instID) && isset($_SESSION["glpiactiveprofile"]) && $_SESSION["glpiactiveprofile"]["interface"] == "central"; $rand = mt_rand(); if ($canedit) { echo "<div id='viewslt{$instID}{$rand}'></div>\n"; echo "<script type='text/javascript' >"; echo "function viewAddSlt{$instID}{$rand}() {"; $params = array('type' => $slt->getType(), 'parenttype' => $sla->getType(), $sla->getForeignKeyField() => $instID, 'id' => -1); Ajax::updateItemJsCode("viewslt{$instID}{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params); echo "}"; echo "</script>"; echo "<div class='center firstbloc'>" . "<a class='vsubmit' href='javascript:viewAddSlt{$instID}{$rand}();'>"; echo __('Add a new SLT') . "</a></div>\n"; } // SLT list $sltList = $slt->find("`slas_id` = '" . $instID . "'"); Session::initNavigateListItems('SLT', sprintf(__('%1$s = %2$s'), $sla::getTypeName(1), $sla->getName())); echo "<div class='spaced'>"; if (count($sltList)) { if ($canedit) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('container' => 'mass' . __CLASS__ . $rand); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixehov'>"; $header_begin = "<tr>"; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit) { $header_top .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_top .= "</th>"; $header_bottom .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_bottom .= "</th>"; } $header_end .= "<th>" . __('Name') . "</th>"; $header_end .= "<th>" . __('Type') . "</th>"; $header_end .= "<th>" . __('Maximum time') . "</th>"; $header_end .= "<th>" . __('Calendar') . "</th>"; echo $header_begin . $header_top . $header_end; foreach ($sltList as $val) { $edit = $canedit ? "style='cursor:pointer' onClick=\"viewEditSlt" . $instID . $val["id"] . "{$rand}();\"" : ''; echo "\n<script type='text/javascript' >\n"; echo "function viewEditSlt" . $instID . $val["id"] . "{$rand}() {\n"; $params = array('type' => $slt->getType(), 'parenttype' => $sla->getType(), $sla->getForeignKeyField() => $instID, 'id' => $val["id"]); Ajax::updateItemJsCode("viewslt{$instID}{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params); echo "};"; echo "</script>\n"; echo "<tr class='tab_bg_1'>"; echo "<td width='10' {$edit}>"; if ($canedit) { Html::showMassiveActionCheckBox($slt->getType(), $val['id']); } echo "</td>"; $slt->getFromDB($val['id']); echo "<td {$edit}>" . $slt->getLink() . "</td>"; echo "<td {$edit}>" . $slt->getSpecificValueToDisplay('type', $slt->fields['type']) . "</td>"; echo "<td {$edit}>"; echo $slt->getSpecificValueToDisplay('number_time', array('number_time' => $slt->fields['number_time'], 'definition_time' => $slt->fields['definition_time'])); echo "</td>"; if (!$sla->fields['calendars_id']) { $link = __('24/7'); } else { if ($sla->fields['calendars_id'] == -1) { $link = __('Calendar of the ticket'); } else { if ($calendar->getFromDB($sla->fields['calendars_id'])) { $link = $calendar->getLink(); } } } echo "<td {$edit}>" . $link . "</td>"; echo "</tr>"; } echo $header_begin . $header_bottom . $header_end; echo "</table>"; if ($canedit) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } } else { echo __('No item to display'); } echo "</div>"; }
static function updateSession() { global $CFG_GLPI; return; $pmSecurity = new self(); $a_data = $pmSecurity->find("`users_id`='" . $_SESSION['glpiID'] . "' " . " AND `session_id`='" . session_id() . "'", '', 1); if (count($a_data) == 1) { $data = current($a_data); $data['session'] = Toolbox::addslashes_deep(exportArrayToDB($_SESSION)); $debug_sql = 0; if ($CFG_GLPI["debug_sql"]) { $debug_sql = $CFG_GLPI["debug_sql"]; $CFG_GLPI["debug_sql"] = 0; } $pmSecurity->update($data); if ($debug_sql) { $CFG_GLPI["debug_sql"] = $debug_sql; } } }