public function execute() { //$this->id = $this->getVariable('id'); if ($this->scheme instanceof One_Scheme) { $scheme = $this->scheme; $idattr = $this->scheme->getIdentityAttribute(); } else { $scheme = One_Repository::getScheme($this->scheme); $idattr = $scheme->getIdentityAttribute(); } $idat = $idattr->getName(); $schemeName = $scheme->getName(); $this->authorize($schemeName, $this->id); $factory = One_Repository::getFactory($schemeName); //$model = $factory->selectOne($this->id); $model = $factory->getInstance($schemeName); if (is_null($model)) { throw new One_Exception('Item could not be found'); } foreach ($scheme->get('attributes') as $attr) { $v = $this->getVariable($attr->getName(), null); if ($v !== null) { $an = $attr->getName(); $model->{$an} = $v; } } //$model->$idat = $this->id; $model->insert(); exit; }
public function countRelated(One_Relation_Adapter $link, One_Model $model, array $options = array()) { $linkName = $link->getName(); // identify the target scheme $source = One_Repository::getScheme($model->getSchemeName()); $target = One_Repository::getScheme($link->getTarget()); $backlinks = $target->getLinks(); $backlink = $backlinks[$link->getLinkId()]; if (!$backlink) { throw new One_Exception('The role "' . $roleName . '" does not exist for this model'); } $at = $source->getIdentityAttribute()->getName(); $column = $this->remoteFK($link, $source, $backlink); // bind the data using the data $localValue = $model->{$at}; // create query and execute $q = One_Repository::selectQuery($link->getTarget()); $q->setOptions($options); if (isset($link->meta['hybrid'])) { $var = $link->meta['hybrid'] . '_scheme'; $q->where($var, 'eq', $source->getName()); } $q->where($column, 'eq', $localValue); return $q->getCount(); }
/** * Class constructor * * @param One_Controller $controller * @param array $options */ public function __construct(One_Controller $controller, array $options = array()) { $this->controller = $controller; $this->options = $options; if (!$this->scheme instanceof One_Scheme) { $this->scheme = One_Repository::getScheme($this->options['scheme']); } }
function execute(&$data, &$parent) { $output = ''; $selected = NULL; $parts = explode(':', trim($this->data), 2); if (count($parts) < 2) { return ''; } $scheme = One_Repository::getScheme($parts[0]); $factory = One_Repository::getFactory($parts[0]); $requested = $parts[1]; $behaviorOptions = $scheme->get('behaviorOptions.linkalias'); if (is_null($behaviorOptions)) { $selected = $factory->selectOne($requested); if (is_null($selected)) { return ''; } $output = $scheme->title() . ' ( ' . $requested . ' )'; } else { if (isset($behaviorOptions['lookup'])) { $query = $factory->selectQuery(); $query->where($behaviorOptions['lookup'], 'eq', $requested); $results = $query->result(); if (count($results) == 0) { return ''; } else { $selected = $results[0]; } } else { $selected = $factory->selectOne($requested); if (is_null($selected)) { return ''; } } if (isset($behaviorOptions['show'])) { $shown = $behaviorOptions['show']; $output = $selected->{$shown}; } else { $output = $scheme->title() . ' ( ' . $requested . ' )'; } } if (trim($output) == '' || is_null($selected)) { return ''; } else { $idAttr = $scheme->getIdentityAttribute()->getName(); $task = 'detail'; $view = 'detail'; if (isset($behaviorOptions['task'])) { $task = $behaviorOptions['task']; } if (isset($behaviorOptions['view'])) { $view = $behaviorOptions['view']; } $link = JRoute::_('index.php?option=com_one&scheme=' . $scheme->getName() . '&task=' . $task . '&view=' . $view . '&id=' . $selected->{$idAttr}); return '<a href="' . $link . '">' . $output . '</a>'; } }
public function execute() { $this->id = $this->getVariable('id'); $fromJQGrid = intval($this->getVariable('fromJqgrid', 0)); if ($this->scheme instanceof One_Scheme) { $scheme = $this->scheme; $idattr = $this->scheme->getIdentityAttribute(); } else { $scheme = One_Repository::getScheme($this->scheme); $idattr = $scheme->getIdentityAttribute(); } $idat = $idattr->getName(); $schemeName = $scheme->getName(); $this->authorize($schemeName, $this->id); $factory = One_Repository::getFactory($schemeName); $model = $factory->selectOne($this->id); if (is_null($model)) { throw new One_Exception('Item could not be found'); } foreach ($scheme->get('attributes') as $attr) { if ($idat != $attr->getName() && !in_array($attr->getName(), array('id', 'oper'))) { $v = $this->getVariable($attr->getName(), null); if ($v !== null) { $an = $attr->getName(); $model->{$an} = $v; } } } $model->{$idat} = $this->id; $model->update(); $context = new One_Context(); $posted = $context->getPost(); // Check for posted reltional fields foreach ($posted as $field => $val) { if (false === strpos($field, ':')) { continue; } // Get the role and targetAttribute to change list($role, $rAttr) = explode(':', $field, 2); // Surround in try-catch block to avoid errors on non-existing relations try { // Only save one-to-many relations $rel = $model->getRelated($role); if (false === is_array($rel) && null !== $rel) { $tIdAttrName = $rel->getScheme()->getIdentityAttribute()->getName(); if ($rAttr == $tIdAttrName) { continue; } $rel->{$rAttr} = $val; $rel->update(); } } catch (Exception $e) { } } exit; }
/** * Respond to get('schemes') * Respond to get('schemes/SCHEMENAME') * * @param $route * @return mixed * @throws Exception */ public static function metaSchemes($route) { switch ($route) { case '': return parent::getSchemeNames(); default: return parent::getScheme($route); } throw new Exception('One cannot get schemes/', $route); }
/** * Create routes for all schemes based on behavior */ protected function _setupRoutes() { // default route for / $this->slim->get('/', array('One_Controller_Rest', 'defaultRouteHandler')); foreach (One_Repository::getSchemeNames() as $schemeName) { $scheme = One_Repository::getScheme($schemeName); if ($scheme->hasBehavior('restable')) { One_Behavior_Restable::slimSetup($this->slim, $scheme); } } }
protected function getData() { $schemeName = $this->scheme; if ($this->scheme instanceof One_Scheme) { $schemeName = $this->scheme->getName(); } $factory = One_Repository::getFactory($schemeName); $query = $factory->selectQuery($this->scheme); $ids = explode(',', $this->options['listFormData']); $idAttr = One_Repository::getScheme($schemeName)->getIdentityAttribute()->getName(); $query->where($idAttr, 'in', $ids); $this->processQueryConditions($query); $results = $query->execute(); return $results; }
/** * Method to get the field input markup. * * @return string The field input markup. * @since 1.6 */ protected function getInput() { $doc = JFactory::getDocument(); // find out which schemes are defined $schemeNames = One_Repository::getSchemeNames(); sort($schemeNames); $options = array(); foreach ($schemeNames as $schemeName) { $currScheme = One_Repository::getScheme($schemeName); if (!isset($currScheme->information['internal']) || isset($currScheme->information['menuonly'])) { $options[] = array("id" => $schemeName, "title" => $currScheme->get('info.title')); } } array_unshift($options, JHTML::_('select.option', '0', '- ' . JText::_('Select scheme') . ' -', 'id', 'title')); return JHTML::_('select.genericlist', $options, '' . $this->formControl . '[' . $this->group . '][' . $this->fieldname . ']', 'class="inputbox" ', 'id', 'title', $this->value, $this->formControl . $this->fieldname); }
/** * Class constructor * * @param One_Controller $controller * @param array $options */ public function __construct(One_Controller $controller, $options = array()) { set_include_path(get_include_path() . PATH_SEPARATOR . One_Vendor::getInstance()->getFilePath() . '/zend'); if (!class_exists('Zend_Locale', false)) { require_once 'Zend/Locale.php'; } parent::__construct($controller, $options); $this->scheme = $options['scheme']; $scheme = One_Repository::getScheme($this->scheme); $calendarOptions = $scheme->get('behaviorOptions.calendar'); $date = $calendarOptions['date']; $enddate = $calendarOptions['enddate']; $time = $calendarOptions['time']; $title = $calendarOptions['title']; $this->dateAttribute = $this->getVariable('dateAttribute', $date ? $date : 'date'); $this->enddateAttribute = $this->getVariable('enddateAttribute', $enddate ? $enddate : NULL); $this->timeAttribute = !is_null($time) ? $this->getVariable('timeAttribute', $time ? $time : 'time') : NULL; $this->titleAttribute = $this->getVariable('titleAttribute', $title ? $title : 'title'); // determine currently requested date $day = trim($this->getVariable('day', '')); $month = trim($this->getVariable('month', '')); $year = trim($this->getVariable('year', '')); if (isset($calendarOptions['startdate']) && $day == '' && $month == '' && $year == '') { if (preg_match('/([0-9]{4}).([0-9]{1,2}).([0-9]{1,2})/', $calendarOptions['startdate'], $matches) > 0 && checkdate($matches[2], $matches[3], $matches[1]) && mktime(0, 0, 0, $matches[2], $matches[3], $matches[1]) > time()) { $day = $matches[3]; $month = $matches[2]; $year = $matches[1]; } else { $day = date('d'); $month = date('m'); $year = date('Y'); } } else { if ($day != '' || $month != '' || $year != '') { $day = $this->getVariable('day', date('d')); $month = $this->getVariable('month', date('m')); $year = $this->getVariable('year', date('Y')); } else { $day = date('d'); $month = date('m'); $year = date('Y'); } } $this->day = $day; $this->month = $month; $this->year = $year; }
public function __construct($config = array()) { parent::__construct($config); $this->schemes = array(); $schemeNames = One_Repository::getSchemeNames(); foreach ($schemeNames as $name) { $scheme = One_Repository::getScheme($name); if ($scheme->get('info.options.internal') != 'internal') { $group = $scheme->get('info.group', 'all'); if (!isset($this->schemes[$group])) { $this->schemes[$group] = array(); } $this->schemes[$group][] = $scheme; $this->schemes['all'][] = $scheme; } } $this->groups = array_keys($this->schemes); }
/** * Is the user authorised to perform the current task * * @param string $task * @param string $schemeName * @param mixed $id * @return boolean */ public static function authorize($task, $schemeName, $id) { // @TODO try defined rule, currently overrides everything $scheme = One_Repository::getScheme($schemeName); $rules = $scheme->getRules($task); // @TODO if none, create generic (behavior-inspired) ruleset if (count($rules)) { foreach ($rules as $rule) { if (!$rule->authorize(array('scheme' => $schemeName, 'id' => $id))) { self::refuse($task, $schemeName, $id); } } } else { if (!in_array($task, array('list', 'detail', 'show', 'jqgrid'))) { self::refuse($task, $schemeName, $id); } } return false; }
/** * Set an alias for a specified role * * @param string $roleName * @param string $alias */ public function setRoleAlias($roleName, $alias) { if (!isset($this->roles[$roleName])) { $link = $this->scheme->getLink($roleName); $scheme = One_Repository::getScheme($link->getTarget()); $resources = $scheme->getResources(); $table = $resources['table']; $this->roles[$roleName]['link'] = $link; $this->roles[$roleName]['scheme'] = $scheme; $this->roles[$roleName]['table'] = $table; } $this->roles[$roleName]['alias'] = $alias; $this->roleAliases[$alias] = $roleName; }
/** * Render the output of the widget and add it to the DOM * * @param One_Model $model * @param One_Dom $d */ protected function _render($model, One_Dom $d) { One_Vendor::requireVendor('jquery/one_loader'); One_Vendor::getInstance()->loadScript('jquery/js/jquery.tagify.js', 'head', 10); if (is_null($this->getCfg('role')) || is_null($this->getCfg('targetAttribute'))) { throw new One_Exception('The Multi-tag widget is only allowed for Many-to-many relations'); } $parts = explode(':', $this->getCfg('role'), 2); $targetAttr = $this->getCfg('targetAttribute'); $link = $model->getScheme()->getLink($parts[1]); if (is_null($link) || !$link->getAdapterType() instanceof One_Relation_Adapter_Manytomany) { throw new One_Exception('The Multi-tag widget is only allowed for Many-to-many relations'); } $tScheme = One_Repository::getScheme($model->getScheme()->getLink($parts[1])->getTarget()); $tIdAttr = $tScheme->getIdentityAttribute()->getName(); // set initial values $value = array(); $values = is_null($this->getValue($model)) ? $this->getDefault() : $this->getValue($model); foreach ($values as $tId) { $tModel = One_Repository::selectOne($tScheme->getName(), $tId); if (null !== $tModel) { $value[$tModel->{$tIdAttr}] = $tModel->{$targetAttr}; } } $data = array('id' => $this->getID(), 'name' => $this->getFormName(), 'events' => $this->getEventsAsString(), 'params' => $this->getParametersAsString(), 'required' => $this->isRequired() ? ' *' : '', 'options' => $this->getOptions(), 'info' => $this->getCfg('info'), 'error' => $this->getCfg('error'), 'class' => $this->getCfg('class'), 'label' => $this->getLabel(), 'lblLast' => $this->getCfg('lblLast')); $dom = $this->parse($model, $data); // $dom->add('<script type="text/javascript" href="'.One_Vendor::getInstance()->getSitePath().'/jquery/js/jquery.tagify.js" />'."\n", '_head'); // $dom->add('<link rel="stylesheet" type="text/css" href="'.One_Vendor::getInstance()->getSitePath().'/jquery/css/tagify-style.css" />'."\n", '_head'); //One_Vendor::getInstance()->loadScript('jquery/js/jquery.tagify.js', 'head', 20); One_Vendor::getInstance()->loadStyle('jquery/css/tagify-style.css', 'head', 20); // Prepare autocomplete tagfield $script = ' var oneTags' . $this->getID() . ' = jQuery("#' . $this->getID() . '").tagify(); oneTags' . $this->getID() . '.tagify("inputField").autocomplete({ source: function(req, add) { req.field = "' . $targetAttr . '"; req.query = "formtags"; //pass request to server jQuery.getJSON("' . One_Config::getInstance()->getSiterootUrl() . One_Config::getInstance()->getAddressOne() . '&scheme=' . $tScheme->getName() . '&task=json", req, function(data) { //create array for response objects var suggestions = []; //process response jQuery.each(data, function(i, val) { var keyval = { "label": val.' . $targetAttr . ', "value": val.' . $tIdAttr . ' }; suggestions.push(keyval); }); //pass array to callback add(suggestions); }); }, position: { of: oneTags' . $this->getID() . '.tagify("containerDiv") }, select: function(e, ui) { oneTags' . $this->getID() . '.tagify("inputField").val(ui.item.label); oneTags' . $this->getID() . '.tagify("add", ui.item.value, ui.item.label); oneTags' . $this->getID() . '.tagify("inputField").val(""); return false; }, focus: function(e, ui) { oneTags' . $this->getID() . '.tagify("inputField").val(ui.item.label); return false; }, change: function(e, ui) { oneTags' . $this->getID() . '.tagify("inputField").val(""); return false; } }); '; foreach ($value as $tId => $tVal) { $script .= ' oneTags' . $this->getID() . '.tagify("add", "' . $tId . '", "' . $tVal . '");'; } // $dom->add($script, '_onload'); One_Vendor::getInstance()->loadScriptDeclaration($script, 'onload', 20); $d->addDom($dom); }
/** * Perform weighted search that returns the results according to matching compatibility * @return array */ protected function performWeightSearch() { $session = One_Repository::getSession(); $allSearchValues = array(); $results = array('count' => 0, 'all' => array(), 'most' => array(), 'some' => array()); // Get all used widgets $form = One_Form_Factory::createForm($this->scheme, $this->searchform); $widgets = $this->getWidgets($form, $this->scheme); $idAttr = $this->scheme->getIdentityAttribute()->getName(); $searchOptions = $this->scheme->get('behaviorOptions.searchable'); $conditions = 0; $weights = array(); $conditionByModel = array(); $specificWeights = array(); foreach ($widgets as $widget) { $widgetData = $widget->getWidgetData(); // Get the widget's name, value and operator // Check whether a widget is a specifier or not $specifier = false; if ($widget->getCfg('specifier')) { $specifier = true; } if (null !== $widgetData['value']) { $allSearchValues[$widgetData['name']] = $widgetData['value']; if (false !== strpos($widgetData['name'], ':')) { $parts = explode(':', $widgetData['name'], 2); $relation = One_Repository::getRelation($parts[0]); // get the used relation $link = $this->scheme->getLink($parts[1]); $targetScheme = One_Repository::getScheme($link->getTarget()); // get the scheme of the related field $tidAttr = $targetScheme->getIdentityAttribute()->getName(); $tSearchOptions = $this->scheme->get('behaviorOptions.searchable'); $wOptions = null; if (method_exists($widget, 'getOptions')) { $wOptions = $widget->getOptions(); } // Get the role of the current scheme as seen from the relation from the target's side $otherRole = null; foreach ($relation->getRoles() as $role) { if ($parts[1] != $role->name) { $otherRole = $role; } } if (null !== $otherRole) { // Dirty trick to enforce the value(s) as an array so they are easier manageable $values = $widgetData['value']; if (!is_array($widgetData['value'])) { $values = array($widgetData['value']); } if (null !== $widgetData['operator']) { $tmpValues = array(); $op = $widgetData['operator']; $allowed = $op->getAllowed(); $opVal = $op->getValue(); if (!is_null($opVal)) { if (in_array($opVal, $allowed)) { $op = $opVal; } else { $op = $allowed['default']; } } else { $op = $allowed['default']; } // Perform special operators foreach ($values as $value) { $tQ = One_Repository::selectQuery($targetScheme->getName()); $tQ->setSelect(array($tidAttr)); $tQ->where($tidAttr, $op, $value); $tmpResults = $tQ->execute(false); foreach ($tmpResults as $tmpResult) { $tmpValues[$tmpResult->{$tidAttr}] = $tmpResult->{$tidAttr}; } } $values = $tmpValues; } // Get all related data // @TODO in the future it could be possible that you don't always get ID's of the related fields, but works for now foreach ($values as $value) { $current = One_Repository::selectOne($targetScheme->getName(), $value); if (!is_null($current)) { if (isset($tSearchOptions['publishField'])) { $tPubField = $searchOptions['publishField']; if (0 == $current->{$tPubField}) { continue; } } $conditions++; $relateds = $current->getRelated($otherRole->name); if (null === $relateds) { continue; } if (!is_array($relateds)) { $relateds = array($relateds); } foreach ($relateds as $related) { if (!isset($weights[$related->{$idAttr}])) { if (false === $specifier) { $weights[$related->{$idAttr}] = 0; } $conditionByModel[$related->{$idAttr}] = array(); } if (!isset($conditionByModel[$related->{$idAttr}][$widgetData['name']])) { $conditionByModel[$related->{$idAttr}][$widgetData['name']] = array(); } if (isset($wOptions[$value])) { $conditionByModel[$related->{$idAttr}][$widgetData['name']][] = $wOptions[$value]; } else { $conditionByModel[$related->{$idAttr}][$widgetData['name']][] = $value; } // if the current widget is a specifier, maintain the data in a separate array to perform an array_intersect to if (true == $specifier) { if (!isset($specificWeights[$related->{$idAttr}])) { $specificWeights[$related->{$idAttr}] = 0; } $specificWeights[$related->{$idAttr}]++; continue; } $weights[$related->{$idAttr}]++; } } } } } else { $values = $widgetData['value']; if (!is_array($widgetData['value'])) { $values = array($widgetData['value']); } if (null !== $widgetData['operator']) { $op = $widgetData['operator']; $allowed = $op->getAllowed(); $opVal = $op->getValue(); if (!is_null($opVal)) { if (in_array($opVal, $allowed)) { $op = $opVal; } else { $op = $allowed['default']; } } else { $op = $allowed['default']; } } else { $op = 'eq'; } foreach ($values as $value) { if ('' != trim($value)) { $conditions++; $cQ = One_Repository::selectQuery($this->scheme->getName()); $cQ->setSelect(array($idAttr)); $cQ->where($widgetData['name'], $op, $value); $tmpResults = $cQ->execute(false); foreach ($tmpResults as $tmpResult) { if (!isset($weights[$tmpResult->{$idAttr}])) { if (false === $specifier) { $weights[$tmpResult->{$idAttr}] = 0; } $conditionByModel[$tmpResult->{$idAttr}] = array(); } if (!isset($conditionByModel[$tmpResult->{$idAttr}][$widgetData['name']])) { $conditionByModel[$tmpResult->{$idAttr}][$widgetData['name']] = array(); } $conditionByModel[$tmpResult->{$idAttr}][$widgetData['name']][] = $value; // if the current widget is a specifier, maintain the data in a separate array to perform an array_intersect to if (true == $specifier) { if (!isset($specificWeights[$tmpResult->{$idAttr}])) { $specificWeights[$tmpResult->{$idAttr}] = 0; } $specificWeights[$tmpResult->{$idAttr}]++; continue; } $weights[$tmpResult->{$idAttr}]++; } } } } } } $tilt = $this->getSearchTilt($conditions); foreach ($weights as $id => $weight) { if (0 < count($specificWeights)) { if (false === array_key_exists($id, $specificWeights)) { unset($weights[$id]); unset($conditionByModel[$id]); continue; } else { $weight += $specificWeights[$id]; } } $model = One_Repository::selectOne($this->scheme->getName(), $id); // using selectOne as the models needed here are already in cache, a global search by there id would take more resources $model->One_Search_Weight = round($weight / $conditions * 100, 2); $model->One_Search_Weight_Conditions = $conditions; $model->One_Search_Weight_ConditionsMet = $weight; $model->One_Search_Weight_ConditionObject = $conditionByModel[$id]; $type = 'some'; if ($conditions == $weight) { $type = 'all'; } elseif ($conditions >= $tilt) { $type = 'most'; } $results[$type][] = $model; $results['count']++; } foreach (array('all', 'most', 'some') as $type) { usort($results[$type], array($this, 'sortResultsByWeight')); } $session->set('results', $results, 'one_search'); return $results; }
/** * Affect the One_Query appropriately * * @param One_Query $q */ public function affectQuery(One_Query $q) { $scheme = $q->getScheme(); $name = $this->getName(); $value = $this->getValue(); $op = $this->getOp($this->getCfg('optype')); if (trim($value) != '') { if (!is_null($this->getCfg('role'))) { $parts = explode(':', $this->getCfg('role')); $role = $parts[1]; $link = $scheme->getLink($role); if (!is_null($link)) { $target = $link->getTarget(); $targetScheme = One_Repository::getScheme($target); $targetAttr = $targetScheme->getIdentityAttribute()->getName(); if (!is_null($targetScheme->getAttribute($targetAttr))) { if (!is_null($op)) { $op->affectQuery($q, $role . ':' . $targetAttr, $value); } else { $q->where($role . ':' . $targetAttr, 'in', $value); // default action } } } } else { if (!is_null($scheme->getAttribute($name))) { if (!is_null($op)) { $op->affectQuery($q, $name, $value); } else { $q->where($name, 'in', $value); // default action } } } } }
/** * Defines a role into the query. * These are used for join-statements * * @access protected * @param string $role */ protected function defineRole($roleName) { if ($roleName == '$self$') { $this->aliases['$self$'] = $this->createAlias(); } else { if (!isset($this->joins[$roleName])) { $alias = $this->query->getRoleAlias($roleName); $role = $this->query->getRole($alias); $this->joins[$roleName] = array(); if (!is_null($alias)) { $role = $this->query->getRole($alias); $this->joins[$roleName]['link'] = $role['link']; $this->joins[$roleName]['scheme'] = $role['scheme']; $this->joins[$roleName]['table'] = $role['table']; $this->joins[$roleName]['alias'] = $role['alias']; $this->aliases[$roleName] = $role['alias']; } else { if (!is_null($role)) { $this->joins[$roleName]['link'] = $role['link']; $this->joins[$roleName]['scheme'] = $role['scheme']; $this->joins[$roleName]['table'] = $role['table']; $this->joins[$roleName]['alias'] = $role['alias']; $this->aliases[$roleName] = $role['alias']; } else { $link = $this->scheme->getLink($roleName); $scheme = One_Repository::getScheme($link->getTarget()); $resources = $scheme->getResources(); if (isset($resources['table'])) { $table = $resources['table']; } else { throw new One_Exception('There is no table defined for the scheme "' . $scheme->getName() . '"'); } $alias = $this->createAlias(); $this->joins[$roleName]['link'] = $link; $this->joins[$roleName]['scheme'] = $scheme; $this->joins[$roleName]['table'] = $table; $this->joins[$roleName]['alias'] = $role['alias']; $this->aliases[$roleName] = $alias; } } } } }
/** * delete a single instance * * @param One_Model $model */ public function delete(One_Model $model) { $scheme = One_Repository::getScheme($model->getSchemeName()); $db = $this->db($scheme); // determine table to insert into $table = $this->getTable($scheme); $sql = 'DELETE FROM ' . $table; $idAttr = $scheme->getIdentityAttribute(); $id = $idAttr->getName(); $value = $model->{$id}; $value = $idAttr->toString(mysql_real_escape_string($value, $db)); $sql .= ' WHERE `' . $id . '` = ' . $value; // execute query if (!mysql_query($sql, $db)) { throw new One_Exception(mysql_error() . $sql); } }
/** * Build the route for the com_one component * * Every one route needs a scheme and a task. Depending on the task, there may be a need for an additional piece * of information. For instance, task=list needs nothing else, but task=detail and taks=edit require an identifier. * * @param array &$query An array of URL arguments * @return array The URL arguments to use to assemble the subsequent URL. * @since 3.3 */ public function build(&$query) { // echo '<div class="well">Building route for com_one query<br/><pre>'; // print_r($query); // echo '</pre>'; $segments = array(); /** * First, check whether we have an Itemid, and see if we can reuse it for this route? This would require that * multiple pieces of information are equal. */ // Get a menu item based on Itemid or currently active $app = JFactory::getApplication(); $menu = $app->getMenu(); $params = JComponentHelper::getParams('com_one'); // We need a menu item. Either the one specified in the query, or the current active one if none specified if (empty($query['Itemid'])) { $menuItem = $menu->getActive(); $menuItemGiven = false; } else { $menuItem = $menu->getItem($query['Itemid']); $menuItemGiven = true; } // Check again, if this Itemid is not a com_one item, do not reuse the Itemid if ($menuItemGiven && isset($menuItem) && $menuItem->component != 'com_one') { $menuItemGiven = false; unset($query['Itemid']); } /** * If there is an Itemid, we can retrieve its information to check upon. Else, we assume that info is an * empty array. */ $menudata = array(); if ($menuItem) { $menudata = $menuItem->query; } // We need to have a scheme in the query or it is an invalid URL if (isset($query['scheme'])) { $schemeName = $query['scheme']; } else { // no scheme, fallback to default return $segments; } // We need to have a task in the query or it is an invalid URL if (isset($query['task'])) { $task = $query['task']; } else { // no task return $segments; } // We MAY have a view in the query if (isset($query['view'])) { $view = $query['view']; } else { $view = ''; } /** * We know what the scheme and task are. The question is how we construct the route, so we need to know whether * this is going to be a special routing defined for this scheme, or the standard routing. * * If the routing is special, we can find the routing by the One_Routing::getAliasForOptions($scheme,$options) * call which needs task+view as parameters. * * If this fails, we need to go to the standard actions. If the scheme's controller implements the action, we * currently treat this as just any task, meaning we have no special route creation info. * * One_Routing::getAliasForOptions has been changed to look through the standard actions if no scheme-specific * route has been located. * * @TODO add a One_Controller::buildRoute/parseRoute pair to handle these special routes * * Else, we ask the standard One_Controller_Action class to tell us what the route should be. In that case, it needs to * answer in the same way as for a special routing. */ $data = array('task' => $task, 'view' => $view); $scheme = One_Repository::getScheme($schemeName); $aliasData = One_Routing::getAliasForOptions($scheme, $data); if ($aliasData !== null) { unset($query['scheme']); unset($query['task']); unset($query['view']); $segments = explode('/', $aliasData['alias']); if ($aliasData['useId'] == 'true') { if (isset($aliasData['aliasField'])) { $aliasField = $aliasData['aliasField']; $schemeQuery = One_Repository::selectQuery($aliasData['schemeName']); $schemeQuery->where($schemeQuery->getScheme()->getIdentityAttribute()->getName(), 'eq', $query['id']); $schemeQuery->setSelect(array($schemeQuery->getScheme()->getIdentityAttribute()->getName(), $aliasField)); $results = $schemeQuery->execute(false); if (count($results)) { $segments[] = $results[0]->{$aliasField}; } unset($query['id']); } else { if (isset($query['id'])) { $segments[] = $query['id']; } } } } else { // nothing } $total = count($segments); for ($i = 0; $i < $total; $i++) { $segments[$i] = str_replace(':', '-', $segments[$i]); } // echo '<pre>'; // print_r($segments); // echo '</pre></div>'; return $segments; }
/** * delete a single instance * * @param One_Model $model * @return void */ public function delete(One_Model $model) { $scheme = One_Repository::getScheme($model->getSchemeName()); $db = $this->db($scheme); // determine table to insert into $table = $this->getTable($scheme); $sql = 'DELETE FROM ' . $table . ' '; $idAttr = $scheme->getIdentityAttribute(); // $id = $idAttr->getName(); $id = $idAttr->getColumn(); $value = $model->{$id}; $value = $idAttr->toString($value); $where = 'WHERE `' . $id . '` = ' . $value; $db->setQuery($sql . $where); $db->query(); return null; }
/** * Load all rows, converted into objects of the specified class * * @param One_Store $store * @param string $sql * @param string $className * @return array */ public function &loadAll(&$store, $sql, $className = 'stdClass') { $scheme = $query->getScheme(); $db = $this->db($scheme); $connectionMeta = $scheme->getResources(); $collection = $db->selectCollection($connectionMeta['collection']); try { $results = $collection->find(); } catch (Exception $e) { throw new One_Exception('Query failed: ' . $e->getMessage()); } $scheme = NULL; if (strtolower($className) != 'stdclass') { $scheme = One_Repository::getScheme($className); } $selection = array(); foreach ($results as $result) { if (null !== $scheme) { $selection[] = $this->arrayToInstance($instanceScheme, $row); } else { $obj = new StdClass(); foreach ($row as $key => $val) { if ('_id' == $key) { $val = (string) $val; } $obj->{$key} = $val; } $selection[] = $obj; } } return $selection; }
public function countRelated(One_Relation_Adapter $link, One_Model $model, array $options = array()) { $linkName = $link->getName(); // identify the target scheme $source = One_Repository::getScheme($model->getSchemeName()); // PD 22OCT08 if ($link->getTarget() == '*') { $col = $link->getName() . '_scheme'; $target = One_Repository::getScheme($model->{$col}); } else { $target = One_Repository::getScheme($link->getTarget()); } // determine the target's identity column $column = $this->localFK($link, $target); // bind the data using the data $localValue = $model[$column]; // create query and execute return One_Repository::selectOne($target->getName(), $localValue) ? 1 : 0; }
/** * Gets all the columns that should be shown in the list * * @return array Array of all columns in the form of object with extra data */ private function getColumns() { $session = One_Repository::getSession(); $exists = true; $filename = One_Locator::locateUsing('list.xml', ONE_LOCATOR_ROOTPATTERN . 'views/' . One_Config::get('app.name') . '/' . $this->scheme->getName() . '/'); if ($filename === null) { $exists = false; } if ($exists) { $xml = @simplexml_load_file($filename); } if ($exists && $xml) { // JL06JAN2009 - if no sorting was clicked, check if the default sort column was set // in the xml file $xmlarray_defs = xmlpm($xml, "/view/columns"); $sort = (string) $xmlarray_defs[0]->attributes()->sort; $limit = (string) $xmlarray_defs[0]->attributes()->limit; if ('' != trim($sort)) { preg_match('/^([^\\+\\-]+)(\\+|\\-)?$/i', $sort, $sortMatch); $this->_sortOrder = 'asc'; $this->_sort = $sortMatch[1]; if (isset($sortMatch[2]) && $sortMatch[2] == '-') { $this->_sortOrder = 'desc'; } } if (0 < abs(intval($limit))) { $this->_limit = abs(intval($limit)); } $xmlarray = $xmlarray_defs[0]->column; $this->_columns = array(); foreach ($xmlarray as $xmlpart) { $tmp = new stdClass(); $name = ''; $setFilter = false; $filterType = 'text'; $filterOptions = array(); $operator = 'contains'; foreach ($xmlpart->attributes() as $key => $val) { switch (strtolower($key)) { case 'name': $tmp->name = (string) $val; break; case 'label': $tmp->label = (string) $val; break; case 'filter': if ($val == 1) { $setFilter = true; } break; case 'filtertype': if (in_array(strtolower($val), array('dropdown', 'text', 'daterange'))) { $filterType = strtolower($val); } break; case 'filteroptions': $options = explode(';', $val); foreach ($options as $option) { $parts = explode('=', $option, 2); $filterOptions[$parts[0]] = $parts[1]; } case 'operator': if (in_array((string) $val, $this->_operators)) { $operator = (string) $val; } default: $tmp->{$key} = (string) $val; } } if ($filterType == 'dropdown' && count($filterOptions) == 0 && trim($tmp->name) != '') { preg_match('/([^:]+)((:)(.+))?/', $tmp->name, $matches); if (!is_null($matches[4])) { $link = $this->scheme->getLink($matches[1]); $target = One_Repository::getScheme($link->getTarget()); $tAtt = $matches[4]; $tFac = One_Repository::getFactory($target->getName()); $tQ = $tFac->selectQuery(); $tQ->setSelect(array($tAtt)); $tQ->setOrder(array($matches[4] . '+')); $options = $tQ->execute(false); foreach ($options as $option) { $filterOptions[$option->{$tAtt}] = $option->{$tAtt}; } } } //PD16SEP09: if no name is given, interpret the body of the tag as CDATA containing nanoScript // TR20100408: change this to only set the name as the label if no name is given. if (!isset($tmp->name)) { $tmp->name = $tmp->label; } //filter operator defaults to contains if (!isset($tmp->name)) { $tmp->operator = 'contains'; } // TR20100408: change this to interpret as nanoscript if a value is passed to the tag if (trim((string) $xmlpart) != '') { $tmp->nScript = (string) $xmlpart; } $this->_columns[$tmp->name] = $tmp; if ($setFilter) { if ($filterType != 'daterange') { $value = JRequest::getVar('s' . $tmp->name, NULL); } else { $value = array(JRequest::getVar('s' . $tmp->name . 'Start', NULL), JRequest::getVar('s' . $tmp->name . 'End', NULL)); } if (is_null($value)) { $value = $session->get($tmp->name, $this->scheme->getName() . '--list'); } $session->set($tmp->name, $value, $this->scheme->getName() . '--list'); $this->_filters[$tmp->name] = array('label' => $tmp->label, 'value' => $value, 'type' => $filterType, 'options' => $filterOptions, 'operator' => $operator); } } } if (is_null($this->_columns)) { $columns = $this->scheme->get('attributes'); $this->_columns = array(); foreach ($columns as $name => $column) { $tmp = new stdClass(); $tmp->label = $column->getName(); $tmp->name = $column->getName(); // TR20100317 used to be $column->column() but should not be used anymore $this->_columns[$tmp->name] = $tmp; } } return $this->_columns; }
/** * Get the value * * @param One_Model $model * @return Mixed */ public function getValue($model) { if (!$model) { return null; } // pick up vars entered entered from an invalidly filled in form $session = One_Repository::getSession(); $posted = $session->get('posted', 'OneFormErrors'); if (!in_array($this->getCfg('one'), array('one', 'yes', 'true', '1')) && isset($posted['oneForm'][$this->getName()])) { return $posted['oneForm'][$this->getName()]; } else { if (isset($posted[$this->getName()])) { return $posted[$this->getName()]; } else { $role = $this->getCfg('role'); if (!is_null($role) && $model instanceof One_Model) { $parts = explode(':', $role); $related = $model->getRelated($parts[1]); $relation = One_Repository::getRelation($parts[0]); $role = $relation->getRole($parts[1]); $relScheme = One_Repository::getScheme($role->schemeName); if ($related instanceof One_Model) { return $related[$relScheme->getIdentityAttribute()->getName()]; } elseif (is_array($related)) { // $related is an array of One_Models $returnValues = array(); foreach ($related as $r) { $returnValues[] = $r[$relScheme->getIdentityAttribute()->getName()]; } return $returnValues; } } else { //PD16FEB10 : add option to pick this up from request if ($this->getCfg('from') != "") { list($source, $key) = preg_split("/:/", $this->getCfg('from')); switch ($source) { case 'request': $from = $_REQUEST; if (!in_array($this->getCfg('one'), array('one', 'yes', 'true', '1'))) { $from = $_REQUEST['oneForm']; } if (isset($from[$key])) { return $from[$key]; } break; } } if ($this->getCfg('novalue') != "novalue") { return $model[$this->getOriginalName()]; } } } } }
/** * Validate whether the form has been submitted correctly * * @param boolean $root * @param One_Form_Container_Abstract $container * @return boolean */ public function validate($root = true, $container = NULL) { $checksOut = true; $oc = new One_Context(); $scheme = $oc->get('scheme'); $schemes = One::meta('schemes'); if (in_array($scheme, $schemes)) { $scheme = One_Repository::getScheme($scheme); $use = $root ? $this : $container; foreach ($use->getContent() as $widget) { if ($widget instanceof One_Form_Widget_Abstract) { $attr = $scheme->getAttribute($widget->getName()); if ($attr instanceof One_Scheme_Attribute) { $type = strtolower(str_replace('One_Scheme_Attribute_Type', '', get_class($attr->getType()))); $widget->setCfg('type', $type); } if (!$widget->validate()) { $checksOut = false; $this->_errors[$widget->getName()]['error'] = $widget->getErrors(); $this->_errors[$widget->getName()]['label'] = $widget->getLabel(); } } else { if ($widget instanceof One_Form_Container_Abstract) { if (!self::validate(false, $widget)) { $checksOut = false; } } } } return $checksOut; } else { return false; } }
public static function fetchAllRoutings() { if (!self::$_schemesFetched) { $schemeNames = One::meta('schemes'); foreach ($schemeNames as $schemeName) { One_Repository::getScheme($schemeName); } self::$_schemesFetched = true; } }
/** * Render the output of the widget and add it to the DOM * * @param One_Model $model * @param One_Dom $d */ protected function _render($model, One_Dom $d) { $this->setCfg('class', 'OneFieldDropdown ' . $this->getCfg('class')); // fetch all data to do with the relationship $parts = explode(':', $this->getCfg('role')); $related = $model->getRelated($parts[1]); $targetAttr = $this->getCfg('targetAttribute'); $triggerOn = intval($this->getCfg('triggerOn')) > 0 ? intval($this->getCfg('triggerOn')) : 2; $scheme = $model->getScheme(); $idAttr = $scheme->getIdentityAttribute()->getName(); $link = $scheme->getLink($parts[1]); $relatedIDs = ''; $options = array(); if (is_array($related) && count($related) > 0) { $relatedIDArray = array(); $idAttr = One_Repository::getScheme($link->getTarget())->getIdentityAttribute()->getName(); $tparts = explode(':', $targetAttr); foreach ($related as $relate) { if (is_null($idAttr)) { $scheme = $model->getScheme(); $idAttr = $scheme->getIdentityAttribute()->getName(); } $value = $relate->{$idAttr}; $shown = ''; foreach ($tparts as $tpart) { $shown .= $relate->{$tpart} . ' '; } $options[$value] = $shown; $relatedIDArray[] = $relate->{$idAttr}; } $relatedIDs = implode('^,^', $relatedIDArray); } $data = array('id' => $this->getID(), 'name' => $this->getFormName(), 'events' => $this->getEventsAsString(), 'params' => $this->getParametersAsString(), 'required' => $this->isRequired() ? ' *' : '', 'value' => is_null($this->getValue($model)) ? $this->getDefault() : $this->getValue($model), 'options' => $options, 'onEmpty' => strtolower($this->getCfg('onEmpty')), 'triggerOn' => $triggerOn, 'scheme' => $scheme, 'link' => $link, 'targetAttr' => $targetAttr, 'modelID' => $model->{$idAttr}, 'relatedIDs' => $relatedIDs, 'info' => $this->getCfg('info'), 'error' => $this->getCfg('error'), 'class' => $this->getCfg('class'), 'label' => $this->getLabel(), 'lblLast' => $this->getCfg('lblLast')); // $dom = new One_Dom(); // dom for head section // // $head = '<script type="text/javascript" src="' . One::getInstance()->getUrl() . 'lib/libraries/js/featherajax.js"></script>'; // $dom->add( $head, '_head' ); $head = ' function setRelatedOptions( selfscheme, scheme, selfId, id, targetAttribute, phrase ) { var self = ""; if( selfscheme == scheme ) self = "&selfId=" + selfId; var aj = new AjaxObject101(); aj.sndReq( "post", "' . One_Config::getInstance()->getUrl() . '/lib/form/ajax/relational.php", "searchscheme=" + scheme + "&dd=f" + id + "&target=" + targetAttribute + "&phrase=" + phrase + self ); } function addChosenOptions( id ) { var dropdown = document.getElementById( "f" + id ); var to = document.getElementById( "t" + id ); for( var i = 0; i < dropdown.length; i++ ) { if( dropdown.options[i].selected == true ) { var option = document.createElement("option"); option.value = dropdown.options[i].value; option.innerHTML = dropdown.options[i].text; var found = false for( var j = 0; j < to.length; j++ ) { if( option.value == to.options[j].value ) { found = true; break; } } if( !found ) { var hidden = document.getElementById( id ); to.appendChild( option ); if( hidden.value != "" ) hidden.value = hidden.value + "^,^" + option.value; else hidden.value = option.value; } } } } function removeChosenOptions( id ) { var to = document.getElementById( "t" + id ); var hidden = document.getElementById( id ); for( var i = ( to.length - 1 ); i >= 0; i-- ) { if( to.options[i].selected == true ) { var pattern = \'((\\^,\\^)?\' + to.options[i].value + \'(\\^,\\^)?)\'; var test = new RegExp( pattern, "gi" ); /* @TODO There is probably an easier way to do this */ hidden.value = hidden.value.replace( test, "" ); hidden.value = hidden.value.replace( /\\^,\\^\\^,\\^/gi, "^,^" ); hidden.value = hidden.value.replace( /^\\^,\\^/gi, "" ); hidden.value = hidden.value.replace( /\\^,\\^$/gi, "" ); to.remove( i ); } } }'; // $dom->add( $head, '_head' ); One_Vendor::getInstance()->loadScript('js/featherajax.js', 200); One_Vendor::getInstance()->loadScriptDeclaration($head, 'head', 200); $content = $this->parse($model, $data); // $d->addDom($dom); $d->addDom($content); }
/** * Parse the given DOMElement into containers and widgets and add them to the form * * @param DOMElement $element * @param One_Form_Container_Abstract $container */ protected static function _parseToForm(DOMElement $element, One_Form_Container_Abstract $container) { $current = strtolower($element->localName); if ($current == 'constraints' || $current == 'constraint') { return NULL; } $widgetClass = self::identifyElement($current); if (is_null($widgetClass)) { return NULL; } if (is_object($widgetClass)) { $widgetClass = get_class($widgetClass); } if (preg_match('/^One_Form_Container/', $widgetClass) && $widgetClass != 'One_Form_Container_Form') { $attributes = array(); $rawAttributes = $element->attributes; for ($i = 0; $i < $rawAttributes->length; $i++) { $attribute = $rawAttributes->item($i); $attributes[$attribute->localName] = $attribute->value; } if (false === isset($attributes['language'])) { $attributes['language'] = strtolower(One_Config::get('app.language')); } $subContainerId = isset($attributes['id']) ? $attributes['id'] : NULL; $subContainer = new $widgetClass($subContainerId, $attributes); // containers can contain other containers or widgets if ($element->hasChildNodes()) { foreach ($element->childNodes as $child) { if ($child instanceof DOMElement) { self::_parseToForm($child, $subContainer); } } } $container->addContainer($subContainer); } else { if ($element->hasAttribute('role')) { // Get cache in preparation of possible option-caching $session = One_Repository::getSession(); $parts = explode(':', $element->getAttribute('role')); if (count($parts) != 2) { throw new One_Exception('You must define a valid role'); } $relation = One_Repository::getRelation($parts[0]); $role = $relation->getRole($parts[1]); $relScheme = One_Repository::getScheme($role->schemeName); // set the name and id of the so it will be recognised as a related field $element->setAttribute('id', 'r__' . $element->getAttribute('role')); $element->setAttribute('name', 'r__' . $element->getAttribute('role')); if ($element->hasAttribute('optionsFrom')) { $sessionCacheName = md5($relScheme->getName() . '#' . $element->getAttribute('optionsFrom')); if (false === $element->hasAttribute('cacheOptions') || $element->hasAttribute('cacheOptions') && false === $session->varExists($sessionCacheName, 'One_Form_Cache')) { $relView = new One_View($relScheme->getName(), $element->getAttribute('optionsFrom')); $rawOptions = trim($relView->show()); $options = json_decode($rawOptions, 1); if (false === is_array($options)) { $options = array(); } if ($element->hasAttribute('cacheOptions')) { $session->set($sessionCacheName, $options, 'One_Form_Cache'); } } else { $options = $session->get($sessionCacheName, 'One_Form_Cache'); } } else { if (!$element->hasAttribute('targetAttribute')) { $targetAttr = $relScheme->getIdentityAttribute()->getName(); } else { $targetAttr = $element->getAttribute('targetAttribute'); } $sessionCacheName = md5($relScheme->getName() . '#' . $targetAttr . '#' . $element->getAttribute('publishedOnly')); if (false === $element->hasAttribute('cacheOptions') || $element->hasAttribute('cacheOptions') && false === $session->varExists($sessionCacheName, 'One_Form_Cache')) { $q = One_Repository::selectQuery($relScheme->getName()); $tparts = explode(':', $targetAttr); foreach ($tparts as $tkey => $tval) { if (in_array(substr($tval, 0, 1), array('(', '['))) { $tparts[$tkey] = substr($tval, 1) . '+'; } else { $tparts[$tkey] = $tval . '+'; } } $q->setOrder($tparts); $results = $q->execute(false); $options = array(); foreach ($results as $result) { $idAttr = $relScheme->getIdentityAttribute()->getName(); $valAttr = $targetAttr; $val = ''; foreach (explode(':', $targetAttr) as $tkey => $tval) { switch (substr($tval, 0, 1)) { case '(': $tval = substr($tval, 1); $val .= '(' . $result->{$tval} . ') '; break; case '[': $tval = substr($tval, 1); $val .= '[' . $result->{$tval} . '] '; break; default: $val .= $result->{$tval} . ' '; break; } } $options[$result->{$idAttr}] = trim($val); } if ($element->hasAttribute('cacheOptions')) { $session->set($sessionCacheName, $options, 'One_Form_Cache'); } } else { $options = $session->get($sessionCacheName, 'One_Form_Cache'); } } $widget = self::determineWidget($container, $element, $widgetClass); if (method_exists($widget, 'setOptionsOnDetermination') && $widget->setOptionsOnDetermination()) { $widget->setOptions($options); } } else { $widget = self::determineWidget($container, $element, $widgetClass); } } }
public function countRelated(One_Relation_Adapter $link, One_Model $model, array $options = array()) { $nRelated = 0; $linkName = $link->getName(); // identify the target scheme $source = One_Repository::getScheme($model->getSchemeName()); $target = One_Repository::getScheme($link->getTarget()); $backlinks = $target->getLinks(); $backlink = $backlinks[$link->getLinkId()]; if (!$backlink) { throw new One_Exception("There is no link with id " . $link->getLinkId() . " in scheme " . $link->getTarget()); } $sourceId = $source->getIdentityAttribute()->getName(); $localValue = $model[$sourceId]; $targetId = $target->getIdentityAttribute()->getName(); // TR20100615 if all stores are equal, do normal join, if not, fetch data in several steps // @TODO This should actually be handled in One_Query if ($source->getConnection()->getName() == $link->meta['connection'] && $link->meta['connection'] == $target->getConnection()->getName()) { $lQ = One_Repository::selectQuery($source); $lQ->setSelect(array($linkName . ':*')); $lQ->where($sourceId, 'eq', $localValue); if (array_key_exists('query', $options) && is_array($options['query']) && count($options['query']) > 0) { foreach ($options['query'] as $qKey => $qOption) { if (count($qOption) == 3) { $options['query'][$qKey][0] = $linkName . ':' . $options['query'][$qKey][0]; } } } $lQ->setOptions($options); $nRelated = $lQ->getCount(); } else { $fkLocal = $link->meta['fk:local']; $fkRemote = $link->meta['fk:remote']; $omtms = One_Repository::getScheme('onemanytomany'); $omtms->setConnection(One_Repository::getConnection($link->meta['connection'])); $omtms->setResources($link->meta); $localAtt = new One_Scheme_Attribute($fkLocal, $source->getIdentityAttribute()->getType()->getName()); $remoteAtt = new One_Scheme_Attribute($fkRemote, $target->getIdentityAttribute()->getType()->getName()); $omtms->addAttribute($localAtt); $omtms->addAttribute($remoteAtt); $joinQ = One_Repository::selectQuery($omtms); $joinQ->setSelect(array($fkRemote)); $joinQ->where($fkLocal, 'eq', $localValue); $rawRelatedIDs = $joinQ->execute(false); $related = array(); if (count($rawRelatedIDs) > 0) { $relatedIDs = array(); foreach ($rawRelatedIDs as $row) { $relatedIDs[] = $row->{$fkRemote}; } $lQ = One_Repository::selectQuery($target); $lQ->where($targetId, 'in', $relatedIDs); $lQ->setOptions($options); $nRelated = $lQ->getCount(); } } return $nRelated; }