/** * Method to test if two values are not equal. To use this rule, the form * XML needs a validate attribute of equals and a field attribute * that is equal to the field to test against. * * @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as as an array container for the field. * For example if the field has name="foo" and the group value is set to "bar" then the * full field name would end up being "bar[foo]". * @param JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form. * @param JForm $form The form object for which the field is being tested. * * @return boolean True if the value is valid, false otherwise. * * @throws InvalidArgumentException * @throws UnexpectedValueException */ public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null) { // If signed integer. if (isset($element['signed']) && RHelperString::toBool($element['signed'])) { $pattern = '/^[+\\-]\\d+$/'; } else { $pattern = '/^\\d+$/'; } return 1 === preg_match($pattern, $value); }
/** * Get the field options as a js string. * * @return string The options. */ public function getOptions() { // Prepare the params. $template = $this->element['template'] ? $this->element['template'] : 'dropdown'; $minuteStep = isset($this->element['minute_step']) && !empty($this->element['minute_step']) ? (int) $this->element['minute_step'] : 15; $secondStep = isset($this->element['second_step']) && !empty($this->element['second_step']) ? (int) $this->element['second_step'] : 15; $showSeconds = RHelperString::toBool($this->element['seconds']) ? 'true' : 'false'; $showMeridian = RHelperString::toBool($this->element['meridian']) ? 'true' : 'false'; $showInputs = RHelperString::toBool($this->element['inputs']) ? 'true' : 'false'; $disableFocus = RHelperString::toBool($this->element['disable_focus']) ? 'true' : 'false'; $modalBackdrop = RHelperString::toBool($this->element['backdrop']) ? 'true' : 'false'; // If we don't have a value. if (empty($this->value)) { $defaultTime = $this->element['default'] ? $this->element['default'] : 'current'; } else { $defaultTime = 'value'; } $options = new JRegistry(); $options->loadArray(array('template' => $template, 'minuteStep' => $minuteStep, 'showSeconds' => $showSeconds, 'secondStep' => $secondStep, 'defaultTime' => $defaultTime, 'showMeridian' => $showMeridian, 'showInputs' => $showInputs, 'disableFocus' => $disableFocus, 'modalBackdrop' => $modalBackdrop)); return $options->toString(); }
/** * Method to cache the last query constructed. * * This method ensures that the query is constructed only once for a given state of the model. * * @return JDatabaseQuery A JDatabaseQuery object */ public function getListQuery() { // Required objects $db = JFactory::getDbo(); // Build the query $query = $db->getQuery(true)->select('s.*')->select('c.name AS country_name')->select('st.name AS state_name')->from('#__jab_speakers AS s')->leftJoin($db->quoteName('#__jab_countries', 'c') . ' ON s.country_id = c.id')->leftJoin($db->quoteName('#__jab_states', 'st') . ' ON s.state_id = st.id')->where('s.id <> 0'); // Join over the users for the checked out user. $query->select('u.name AS checked_out'); $query->leftJoin('#__users AS u ON u.id = s.checked_out'); // Join over the users for the author. $query->select('ua.name AS created_by'); $query->leftJoin('#__users AS ua ON ua.id = s.created_by'); // Join over the users for the editor. $query->select('ub.name AS modified_by'); $query->leftJoin('#__users AS ub ON ub.id = s.modified_by'); // Join language $query->select('l.title AS language_title'); $query->join('LEFT', $db->quoteName('#__languages') . ' AS l ON l.lang_code = s.language'); // Filter on the language. if ($language = $this->getState('filter.language')) { $query->where('s.language = ' . $db->quote($language)); } // Filter: like / search $search = $this->getState('filter.search'); if (!empty($search)) { $like = '%' . $search . '%'; $query->where('(' . 's.name LIKE ' . $db->quote($like) . ' OR c.name LIKE ' . $db->quote($like) . ' OR st.name LIKE ' . $db->quote($like) . ')'); } // Filter: published $published = RHelperString::multipleSanitised($this->getState('filter.published')); if (!empty($published)) { if (count($published) == 1) { if (is_numeric($published[0])) { $query->where('s.published = ' . (int) $published[0]); } } else { $query->where('s.published IN (' . implode(',', $published) . ')'); } } // Get the ordering modifiers $orderList = $this->getState('list.ordering'); $directionList = $this->getState('list.direction'); $random = $this->getState('list.random'); // Random order selected if ($orderList == 'random') { $orderList = 'RAND()'; } $order = !empty($orderList) ? $orderList : 's.name'; $direction = !empty($directionList) ? $directionList : 'ASC'; $query->order($db->escape($order) . ' ' . $db->escape($direction)); return $query; }
/** * Build an SQL query to load the list data. * * @return JDatabaseQuery * * @since 1.6 */ protected function getListQuery() { // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); // Select the required fields from the table. $query->select("c.*"); $query->from('#__jab_countries AS c'); // Join over the users for the checked out user. $query->select('u.name AS checked_out'); $query->leftJoin('#__users AS u ON u.id = c.checked_out'); // Join over the users for the author. $query->select('ua.name AS created_by'); $query->leftJoin('#__users AS ua ON ua.id = c.created_by'); // Join over the users for the editor. $query->select('ub.name AS modified_by'); $query->leftJoin('#__users AS ub ON ub.id = c.modified_by'); // Join language $query->select('l.title AS language_title'); $query->join('LEFT', $db->quoteName('#__languages') . ' AS l ON l.lang_code = c.language'); // Filter on the language. if ($language = $this->getState('filter.language')) { $query->where('c.language = ' . $db->quote($language)); } // Filter: state $states = RHelperString::multipleSanitised($this->getState('filter.published')); if (!empty($states)) { if (count($states) == 1) { if (is_numeric($states[0])) { $query->where('c.state = ' . (int) $states[0]); } } else { $query->where('c.state IN (' . implode(',', $states) . ')'); } } // Filter: like / search $search = $this->getState('filter.search'); if (!empty($search)) { $like = '%' . $search . '%'; $query->where('(' . 'c.name LIKE ' . $db->quote($like) . ' OR l.title LIKE ' . $db->quote($like) . ')'); } // Get the ordering modifiers $orderList = $this->getState('list.ordering'); $directionList = $this->getState('list.direction'); $random = $this->getState('list.random'); // Random order selected if ($orderList == 'random') { $orderList = 'RAND()'; } $order = !empty($orderList) ? $orderList : 'c.name'; $direction = !empty($directionList) ? $directionList : 'ASC'; $query->order($db->escape($order) . ' ' . $db->escape($direction)); return $query; }