public static function listProfiles(xPDO &$xpdo, array $criteria = array(), array $sort = array('id' => 'ASC'), $limit = 0, $offset = 0) { /* query for profiles */ $c = $xpdo->newQuery('modFormCustomizationProfile'); $c->select(array( 'modFormCustomizationProfile.*', )); $c->select(' (SELECT GROUP_CONCAT(UserGroup.name) FROM '.$xpdo->getTableName('modUserGroup').' AS UserGroup INNER JOIN '.$xpdo->getTableName('modFormCustomizationProfileUserGroup').' AS fcpug ON fcpug.usergroup = UserGroup.id WHERE fcpug.profile = modFormCustomizationProfile.id ) AS usergroups '); $c->where($criteria,null,2);// also log issue in remine to look at this usage of where() $count = $xpdo->getCount('modFormCustomizationProfile',$c); foreach($sort as $field=> $dir) { $c->sortby($xpdo->getSelectColumns('modFormCustomizationProfile','modFormCustomizationProfile','',array($field)),$dir); } if ((int) $limit > 0) { $c->limit((int) $limit, (int) $offset); } return array( 'count'=> $count, 'collection'=> $xpdo->getCollection('modFormCustomizationProfile',$c) ); }
/** * Constructor * * Do not call the constructor directly; see {@link xPDO::newObject()}. * * All derivatives of xPDOObject must redeclare this method, and must call * the parent method explicitly before any additional logic is executed, e.g. * * <code> * public function __construct(xPDO & $xpdo) { * parent :: __construct($xpdo); * // Any additional constructor tasks here * } * </code> * * @access public * @param xPDO &$xpdo A reference to a valid xPDO instance. * @return xPDOObject */ public function __construct(xPDO &$xpdo) { $this->xpdo =& $xpdo; $this->container = $xpdo->config['dbname']; $this->_class = get_class($this); $pos = strrpos($this->_class, '_'); if ($pos !== false && substr($this->_class, $pos + 1) == $xpdo->config['dbtype']) { $this->_class = substr($this->_class, 0, $pos); } $this->_package = $xpdo->getPackage($this->_class); $this->_alias = $this->_class; $this->_table = $xpdo->getTableName($this->_class); $this->_tableMeta = $xpdo->getTableMeta($this->_class); $this->_fields = $xpdo->getFields($this->_class); $this->_fieldMeta = $xpdo->getFieldMeta($this->_class); $this->_fieldAliases = $xpdo->getFieldAliases($this->_class); $this->_aggregates = $xpdo->getAggregates($this->_class); $this->_composites = $xpdo->getComposites($this->_class); if ($relatedObjs = array_merge($this->_aggregates, $this->_composites)) { foreach ($relatedObjs as $aAlias => $aMeta) { if (!array_key_exists($aAlias, $this->_relatedObjects)) { if ($aMeta['cardinality'] == 'many') { $this->_relatedObjects[$aAlias] = array(); } else { $this->_relatedObjects[$aAlias] = null; } } } } foreach ($this->_fieldAliases as $fieldAlias => $field) { $this->addFieldAlias($field, $fieldAlias); } $this->setDirty(); }
/** * Constructor * * Do not call the constructor directly; see {@link xPDO::newObject()}. * * All derivatives of xPDOObject must redeclare this method, and must call * the parent method explicitly before any additional logic is executed, e.g. * * <code> * protected function __construct(& $xpdo) { * parent :: __construct($xpdo); * // Any additional constructor tasks here * } * </code> * * @access public * @param xPDO &$xpdo A reference to a valid xPDO instance. * @return xPDOObject */ public function __construct(xPDO &$xpdo) { $this->container = $xpdo->config['dbname']; $this->_class = get_class($this); $pos = strrpos($this->_class, '_'); if ($pos !== false && substr($this->_class, $pos + 1) == $xpdo->config['dbtype']) { $this->_class = substr($this->_class, 0, $pos); } $this->_package = $xpdo->getPackage($this->_class); $this->_alias = $this->_class; $this->_table = $xpdo->getTableName($this->_class); $this->_tableMeta = $xpdo->getTableMeta($this->_class); $this->_fields = $xpdo->getFields($this->_class); $this->_fieldMeta = $xpdo->getFieldMeta($this->_class); $this->_aggregates = $xpdo->getAggregates($this->_class); $this->_composites = $xpdo->getComposites($this->_class); $this->_options[xPDO::OPT_CALLBACK_ON_REMOVE] = isset($xpdo->config[xPDO::OPT_CALLBACK_ON_REMOVE]) && !empty($xpdo->config[xPDO::OPT_CALLBACK_ON_REMOVE]) ? $xpdo->config[xPDO::OPT_CALLBACK_ON_REMOVE] : null; $this->_options[xPDO::OPT_CALLBACK_ON_SAVE] = isset($xpdo->config[xPDO::OPT_CALLBACK_ON_SAVE]) && !empty($xpdo->config[xPDO::OPT_CALLBACK_ON_SAVE]) ? $xpdo->config[xPDO::OPT_CALLBACK_ON_SAVE] : null; $this->_options[xPDO::OPT_HYDRATE_RELATED_OBJECTS] = isset($xpdo->config[xPDO::OPT_HYDRATE_RELATED_OBJECTS]) && $xpdo->config[xPDO::OPT_HYDRATE_RELATED_OBJECTS]; $this->_options[xPDO::OPT_HYDRATE_ADHOC_FIELDS] = isset($xpdo->config[xPDO::OPT_HYDRATE_ADHOC_FIELDS]) && $xpdo->config[xPDO::OPT_HYDRATE_ADHOC_FIELDS]; $this->_options[xPDO::OPT_HYDRATE_FIELDS] = isset($xpdo->config[xPDO::OPT_HYDRATE_FIELDS]) && $xpdo->config[xPDO::OPT_HYDRATE_FIELDS]; $this->_options[xPDO::OPT_ON_SET_STRIPSLASHES] = isset($xpdo->config[xPDO::OPT_ON_SET_STRIPSLASHES]) && $xpdo->config[xPDO::OPT_ON_SET_STRIPSLASHES]; $this->_options[xPDO::OPT_VALIDATE_ON_SAVE] = isset($xpdo->config[xPDO::OPT_VALIDATE_ON_SAVE]) && $xpdo->config[xPDO::OPT_VALIDATE_ON_SAVE]; $this->_options[xPDO::OPT_VALIDATOR_CLASS] = isset($xpdo->config[xPDO::OPT_VALIDATOR_CLASS]) ? $xpdo->config[xPDO::OPT_VALIDATOR_CLASS] : ''; $classVars = array(); if ($relatedObjs = array_merge($this->_aggregates, $this->_composites)) { if ($this->_options[xPDO::OPT_HYDRATE_RELATED_OBJECTS]) { $classVars = get_object_vars($this); } foreach ($relatedObjs as $aAlias => $aMeta) { if (!array_key_exists($aAlias, $this->_relatedObjects)) { if ($aMeta['cardinality'] == 'many') { $this->_relatedObjects[$aAlias] = array(); } else { $this->_relatedObjects[$aAlias] = null; } } if ($this->_options[xPDO::OPT_HYDRATE_RELATED_OBJECTS] && !array_key_exists($aAlias, $classVars)) { $this->{$aAlias} =& $this->_relatedObjects[$aAlias]; $classVars[$aAlias] = 1; } } } if ($this->_options[xPDO::OPT_HYDRATE_FIELDS]) { if (!$this->_options[xPDO::OPT_HYDRATE_RELATED_OBJECTS]) { $classVars = get_object_vars($this); } foreach ($this->_fields as $fldKey => $fldVal) { if (!array_key_exists($fldKey, $classVars)) { $this->{$fldKey} =& $this->_fields[$fldKey]; } } } $this->setDirty(); $this->xpdo =& $xpdo; }
/** * Constructor * * Do not call the constructor directly; see {@link xPDO::newObject()}. * * All derivatives of xPDOObject must redeclare this method, and must call * the parent method explicitly before any additional logic is executed, e.g. * * <code> * public function __construct(xPDO & $xpdo) { * parent :: __construct($xpdo); * // Any additional constructor tasks here * } * </code> * * @access public * @param xPDO &$xpdo A reference to a valid xPDO instance. * @return xPDOObject */ public function __construct(xPDO &$xpdo) { $this->xpdo =& $xpdo; $this->container = $xpdo->config['dbname']; $this->_class = get_class($this); $pos = strrpos($this->_class, '_'); if ($pos !== false && substr($this->_class, $pos + 1) == $xpdo->config['dbtype']) { $this->_class = substr($this->_class, 0, $pos); } $this->_package = $xpdo->getPackage($this->_class); $this->_alias = $this->_class; $this->_table = $xpdo->getTableName($this->_class); $this->_tableMeta = $xpdo->getTableMeta($this->_class); $this->_fields = $xpdo->getFields($this->_class); $this->_fieldMeta = $xpdo->getFieldMeta($this->_class); $this->_fieldAliases = $xpdo->getFieldAliases($this->_class); $this->_aggregates = $xpdo->getAggregates($this->_class); $this->_composites = $xpdo->getComposites($this->_class); $classVars = array(); if ($relatedObjs = array_merge($this->_aggregates, $this->_composites)) { if ($this->getOption(xPDO::OPT_HYDRATE_RELATED_OBJECTS)) { $classVars = get_object_vars($this); } foreach ($relatedObjs as $aAlias => $aMeta) { if (!array_key_exists($aAlias, $this->_relatedObjects)) { if ($aMeta['cardinality'] == 'many') { $this->_relatedObjects[$aAlias] = array(); } else { $this->_relatedObjects[$aAlias] = null; } } if ($this->getOption(xPDO::OPT_HYDRATE_RELATED_OBJECTS) && !array_key_exists($aAlias, $classVars)) { $this->{$aAlias} =& $this->_relatedObjects[$aAlias]; $classVars[$aAlias] = 1; } } } if ($this->getOption(xPDO::OPT_HYDRATE_FIELDS)) { if (!$this->getOption(xPDO::OPT_HYDRATE_RELATED_OBJECTS)) { $classVars = get_object_vars($this); } foreach ($this->_fields as $fldKey => $fldVal) { if (!array_key_exists($fldKey, $classVars)) { $this->{$fldKey} =& $this->_fields[$fldKey]; } } } foreach ($this->_fieldAliases as $fieldAlias => $field) { $this->addFieldAlias($field, $fieldAlias); } $this->setDirty(); }
/** * Find all policies for this object * * @param string $context * @return array */ public function findPolicy($context = '') { $policy = array(); $enabled = true; $context = 'mgr'; if ($context === $this->xpdo->context->get('key')) { $enabled = (bool) $this->xpdo->getOption('access_media_source_enabled', null, true); } elseif ($this->xpdo->getContext($context)) { $enabled = (bool) $this->xpdo->contexts[$context]->getOption('access_media_source_enabled', true); } if ($enabled) { if (empty($this->_policies) || !isset($this->_policies[$context])) { $accessTable = $this->xpdo->getTableName('sources.modAccessMediaSource'); $sourceTable = $this->xpdo->getTableName('sources.modMediaSource'); $policyTable = $this->xpdo->getTableName('modAccessPolicy'); $sql = "SELECT Acl.target, Acl.principal, Acl.authority, Acl.policy, Policy.data FROM {$accessTable} Acl " . "LEFT JOIN {$policyTable} Policy ON Policy.id = Acl.policy " . "JOIN {$sourceTable} Source ON Acl.principal_class = 'modUserGroup' " . "AND (Acl.context_key = :context OR Acl.context_key IS NULL OR Acl.context_key = '') " . "AND Source.id = Acl.target " . "WHERE Acl.target = :source " . "GROUP BY Acl.target, Acl.principal, Acl.authority, Acl.policy"; $bindings = array(':source' => $this->get('id'), ':context' => $context); $query = new xPDOCriteria($this->xpdo, $sql, $bindings); if ($query->stmt && $query->stmt->execute()) { while ($row = $query->stmt->fetch(PDO::FETCH_ASSOC)) { $policy['sources.modAccessMediaSource'][$row['target']][] = array('principal' => $row['principal'], 'authority' => $row['authority'], 'policy' => $row['data'] ? $this->xpdo->fromJSON($row['data'], true) : array()); } } $this->_policies[$context] = $policy; } else { $policy = $this->_policies[$context]; } } return $policy; }
/** * Mark all posts in this thread as read * @static * @param xPDO $modx * @param string $type * @return bool */ public static function readAll(xPDO &$modx, $type = 'message') { $userId = $modx->discuss->user->get('id'); $sql = 'SELECT `disThread`.`id` FROM ' . $modx->getTableName('disThread') . ' `disThread` INNER JOIN ' . $modx->getTableName('disThreadUser') . ' `ThreadUser` ON `ThreadUser`.`thread` = `disThread`.`id` LEFT JOIN ' . $modx->getTableName('disThreadRead') . ' `ThreadRead` ON `ThreadRead`.`thread` = `disThread`.`id` WHERE `ThreadUser`.`user` = ' . $userId . ' AND `ThreadRead`.`id` IS NULL AND `private` = 1 ORDER BY `disThread`.`id` DESC'; $stmt = $modx->query($sql); if (!$stmt) { return false; } while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $read = $modx->getCount('disThreadRead', array('thread' => $row['id'], 'user' => $userId)); if ($read == 0) { $read = $modx->newObject('disThreadRead'); $read->fromArray(array('thread' => $row['id'], 'board' => 0, 'user' => $userId)); $read->save(); } } $stmt->closeCursor(); return true; }