Exemplo n.º 1
0
 protected function handler_main(Collection $users, array $fields)
 {
     $joins = array();
     $cols = array();
     $loc_fields = array_intersect($fields, self::$natives);
     if (!empty($loc_fields)) {
         $cols['a'] = $loc_fields;
     }
     if (in_array('poly', $fields)) {
         $cols['p'] = array('poly');
         $joins['p'] = PlSqlJoin::left('poly', '$ME.uid = a.uid');
     }
     if (in_array('default_filters', $fields)) {
         $cols['udf'] = array('default_filters');
         $joins['udf'] = PlSqlJoin::left('users_defaultfilters', '$ME.uid = a.uid');
     }
     $this->helper_main($users, $cols, $joins);
 }
Exemplo n.º 2
0
 protected function userJoins()
 {
     $joins = array();
     if ($this->with_user) {
         $joins['cu'] = PlSqlJoin::left('castes_users', '$ME.cid = c.cid AND ($ME.visibility IN {?} OR $ME.uid = {?})', S::user()->visibleGids(), S::user()->id());
     }
     return $joins;
 }
Exemplo n.º 3
0
 protected function groupJoins()
 {
     $joins = array();
     if ($this->with_groups > 0) {
         for ($i = 1; $i <= $this->with_groups; $i++) {
             $joins['rg' . $i] = PlSqlJoin::inner('rooms_groups', '$ME.rid = r.rid');
         }
     }
     return $joins;
 }
Exemplo n.º 4
0
 /** Since this method might perform inner joins on tables which have been
  * joined previously (e.g when using addVisibilityFieldFilter), it has to
  * come after the Joins() methods for those tables.
  * This is due to the implementation logic for discovering joins and the
  * ordering used by PHP introspection.
  */
 protected function visibilityJoins()
 {
     $joins = array();
     foreach ($this->vlevels as $level => $sub) {
         $joins[$sub] = PlSqlJoin::inner('profile_visibility_enum', '$ME.access_level = {?}', $level);
     }
     foreach ($this->vfields as $field => $sub) {
         $joins[$sub] = PlSqlJoin::inner('profile_visibility_enum', '$ME.access_level = ' . $field);
     }
     return $joins;
 }
Exemplo n.º 5
0
 protected function roomJoins()
 {
     $joins = array();
     if ($this->with_room) {
         $joins['rg'] = PlSqlJoin::left('rooms_groups', '$ME.gid = g.gid');
         $joins['r'] = PlSqlJoin::left('rooms', '$ME.rid = rg.rid');
     }
     return $joins;
 }
Exemplo n.º 6
0
 protected function helper_main(Collection $metas, array $cols, array $joins)
 {
     $table = $this->schema->table();
     $as = $this->schema->tableAs();
     $id = $this->schema->id();
     $sql_fields = self::arrayToSqlCols($cols);
     $sql_joins = PlSqlJoin::formatJoins($joins, array());
     $collections = array();
     foreach ($cols as $fields) {
         foreach ($fields as $field) {
             if ($this->schema->isCollection($field)) {
                 // TODO: is this code used ?
                 //$collections[$field] = new Collection($this->schema->collectionType($field));
                 throw new Exception("Oops, there is a main handler for collections now ?");
             } elseif (!empty($this->subs) && array_key_exists($field, $this->subs)) {
                 $collections[$field] = new Collection($this->schema->objectType($field));
             }
         }
     }
     $iter = XDB::iterator("SELECT  {$as}.{$id} AS id, {$sql_fields}\n                                 FROM  {$table} AS {$as}\n                                       {$sql_joins}\n                                WHERE  {$as}.{$id} IN {?}", $metas->ids());
     while ($datas = $iter->next()) {
         foreach ($datas as $key => $value) {
             if ($this->schema->isObject($key)) {
                 $class = $this->schema->objectType($key);
                 $datas[$key] = new $class($value);
             }
             if (array_key_exists($key, $collections) && $value !== null) {
                 $datas[$key] = $collections[$key]->addget($value);
             }
             if ($value === null) {
                 /*
                  * /!\ Null in the DB means false in here.
                  * Therefore Boolean fields must *not* be nullable !
                  */
                 $datas[$key] = false;
             }
         }
         $metas->get($datas['id'])->fillFromArray($datas);
     }
     foreach ($collections as $field => $collection) {
         $collection->select($this->subs[$field]);
     }
 }
Exemplo n.º 7
0
 protected function activityInstanceJoins()
 {
     $joins = array();
     if ($this->with_activityinstances > 0) {
         for ($i = 1; $i <= $this->with_activityinstances; $i++) {
             $joins['ai' . $i] = PlSqlJoin::inner('activities_participants', '$ME.participant = a.uid');
         }
     }
     return $joins;
 }
Exemplo n.º 8
0
 protected function sizeJoins()
 {
     $joins = array();
     if ($this->with_size) {
         $joins['i_s'] = PlSqlJoin::left('images_sizes', '$ME.iid = i.iid');
     }
     return $joins;
 }
Exemplo n.º 9
0
 public static function batchSelect(array $wikis, $options = null)
 {
     if (empty($wikis)) {
         return;
     }
     $bits = self::optionsToBits($options);
     $wikis = array_combine(self::toIds($wikis), $wikis);
     $joins = array();
     $cols = array();
     if ($bits & self::SELECT_BASE) {
         $cols['w'] = array('name', 'comments');
     }
     if ($bits & self::SELECT_COUNT || $bits & self::SELECT_VERSION) {
         $cols[-1] = array('COUNT(wv.version) AS count');
         $joins['wv'] = PlSqlJoin::left('wiki_version', '$ME.wid = w.wid');
     }
     if (!empty($cols)) {
         $iter = XDB::iterator('SELECT  w.wid AS id, ' . self::arrayToSqlCols($cols) . '
                                  FROM  wiki AS w
                                        ' . PlSqlJoin::formatJoins($joins, array()) . '
                                 WHERE  w.wid IN {?}
                              GROUP BY  w.wid', array_keys($wikis));
         while ($datas = $iter->next()) {
             $wikis[$datas['id']]->fillFromArray($datas);
         }
     }
     // Load last version
     if ($bits & self::SELECT_VERSION) {
         if (!isset($options[self::SELECT_VERSION])) {
             $opts = array('versions' => array('last'));
         } else {
             $opts = $options[self::SELECT_VERSION];
         }
         $conds = array();
         foreach ($wikis as $w) {
             if ($w->versions == null) {
                 $w->versions = array();
             }
             $versions = array();
             if (in_array('last', $opts['versions'])) {
                 $versions[] = $w->count();
             }
             foreach ($opts['versions'] as $version) {
                 if ($version != 'last') {
                     $versions[] = $version;
                 }
             }
             if (!empty($versions)) {
                 $conds[] = XDB::format('( wid = {?} AND version IN {?} )', $w->id(), $versions);
             }
         }
         $iter = XDB::iterator('SELECT  wid AS id, version, wrote, writer, content
                                  FROM  wiki_version
                                 WHERE  ' . implode(' OR ', $conds));
         $writers = new Collection('User');
         while ($datas = $iter->next()) {
             $writer = $writers->addget($datas['writer']);
             $wikis[$datas['id']]->versions[$datas['version']] = array('wrote' => $datas['wrote'], 'writer' => $writer, 'content' => $datas['content']);
         }
         if (isset($opts['options'])) {
             $writers->select($opts['options']);
         }
     }
 }