Example #1
0
 /**
  * Returns array of fields allowed for user
  * @method exportArray
  * @param {array} $options=array()
  *  Options can include:
  *  "asUserId" => Defaults to the logged in user, or "" if not logged in
  *	If access is not set for the stream it will be calculated for <code>$asUserId</code>
  * @return {array}
  */
 function exportArray($options = null)
 {
     $asUserId = isset($options['asUserId']) ? $options['asUserId'] : null;
     if (!isset($asUserId)) {
         $user = Users::loggedInUser();
         $asUserId = $user ? $user->id : '';
     }
     $this->calculateAccess($asUserId);
     if ($this->testReadLevel('content')) {
         $result = $this->toArray();
         $result['icon'] = $this->iconUrl();
     } else {
         if (!$this->testReadLevel('see')) {
             return array();
         }
         $result = array();
         $default = array('publisherId', 'name', 'type', 'title', 'icon', 'insertedTime', 'updatedTime');
         if (isset($this->type)) {
             $fields = array_merge($default, Q_Config::get('Streams', 'types', $this->type, 'see', array()));
         }
         foreach ($fields as $field) {
             $result[$field] = $field === 'icon' ? $this->iconUrl() : $this->{$field};
         }
     }
     $classes = Streams::getExtendClasses($this->type);
     $fieldNames = array();
     foreach ($classes as $k => $v) {
         foreach ($v as $f) {
             foreach ($fieldNames as $key) {
                 $result[$f] = isset($this->{$f}) ? $this->{$f} : null;
             }
         }
     }
     $result['access'] = array('readLevel' => $this->get('readLevel', $this->readLevel), 'writeLevel' => $this->get('writeLevel', $this->writeLevel), 'adminLevel' => $this->get('adminLevel', $this->adminLevel));
     $result['isRequired'] = $this->isRequired();
     return $result;
 }
Example #2
0
 protected static function afterFetchExtended($publisherId, $streams)
 {
     if (!$streams) {
         return;
     }
     $classes = array();
     $rows = array();
     $streamNamesByType = array();
     foreach ($streams as $stream) {
         if (!$stream) {
             continue;
         }
         $streamNamesByType[$stream->type][] = $stream->name;
     }
     $classes = array();
     foreach ($streams as $stream) {
         if (!$stream) {
             continue;
         }
         $type = $stream->type;
         if (!isset($classes[$type])) {
             $classes[$type] = Streams::getExtendClasses($type);
             foreach ($classes[$type] as $className => $fieldNames) {
                 $rows[$className] = call_user_func(array($className, 'select'), '*')->where(array('publisherId' => $publisherId, 'streamName' => $streamNamesByType[$type]))->fetchDbRows(null, '', 'streamName');
             }
         }
     }
     foreach ($streams as $stream) {
         if (!$stream) {
             continue;
         }
         $streamName = $stream->name;
         foreach ($classes[$stream->type] as $className => $fieldNames) {
             if (empty($rows[$className][$streamName])) {
                 continue;
             }
             $row = $stream->rows[$className] = $rows[$className][$streamName];
             $row->set('Streams_Stream', $stream);
             foreach ($fieldNames as $f) {
                 if (!isset($rows[$className][$streamName])) {
                     continue;
                 }
                 $stream->{$f} = $rows[$className][$streamName]->{$f};
             }
         }
     }
 }