Пример #1
0
 /**
  * @{inheritdoc}
  */
 public function toSerializableArray($entity)
 {
     $data = parent::toSerializableArray($entity);
     $data['username'] = $entity->username;
     if (KService::has('com:people.viewer') && KService::get('com:people.viewer')->eql($entity)) {
         $data['email'] = $entity->email;
     }
     return $data;
 }
Пример #2
0
 protected function _beforeRepositoryFetch($context)
 {
     if (KService::has('com:people.viewer') && is_person(get_viewer()) && get_viewer()->admin()) {
         return;
     }
     $query = $context->query;
     $config = pick($query->privacy, new KConfig());
     $config->append(array('viewer' => get_viewer()));
     $where = $this->buildCondition(get_viewer(), $config);
     $query->where($where);
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 protected function _beforeRepositoryFetch(KCommandContext $context)
 {
     if (KService::has('com:people.viewer') && is_person(get_viewer()) && get_viewer()->admin()) {
         return;
     }
     $query = $context->query;
     $repository = $query->getRepository();
     $config = pick($query->privacy, new KConfig());
     $config->append(array('visible_to_leaders' => true, 'viewer' => get_viewer(), 'graph_check' => true));
     $where = $this->buildCondition('@col(id)', $config, '@col(access)');
     $query->where($where);
 }
Пример #4
0
 /**
  * Get a service api
  *
  * @param  string $service The service name.
  * 
  * @return ComConnectOauthApiAbstract
  */
 public static function getAPI($service)
 {
     $service = strtolower($service);
     $identifier = 'com://site/connect.oauth.service.' . $service;
     if (!KService::has($identifier)) {
         $config = array();
         $config['consumer'] = self::getConsumer($service);
         $config['enabled'] = self::enabled($service);
         KService::set($identifier, KService::get($identifier, $config));
     }
     return KService::get($identifier);
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 protected function _beforeQuerySelect(KCommandContext $context)
 {
     if (KService::has('com:people.viewer') && is_person(get_viewer()) && get_viewer()->admin()) {
         return;
     }
     $query = $context->query;
     $repository = $query->getRepository();
     $config = pick($query->privacy, new KConfig());
     $config->append(array('visible_to_leaders' => true, 'viewer' => KService::get('com:people.viewer'), 'graph_check' => true));
     $query->getRepository()->addBehavior('ownable');
     //do a left join operation just in case an owner is missing
     $query->link('owner', array('type' => 'weak', 'bind_type' => false));
     $config->append(array('use_access_column' => '@col(access)'));
     $c1 = $this->buildCondition('@col(owner.id)', $config, '@col(owner.access)');
     $c2 = $this->buildCondition('@col(owner.id)', $config, $config->use_access_column);
     $where = "IF({$c1}, {$c2}, 0)";
     $query->where($where);
 }
Пример #6
0
 /**
  * Adds a filter to the query based on the access mode
  *
  * @param  KCommandContext $context
  * 
  * @return void
  */
 protected function _beforeRepositoryFetch(KCommandContext $context)
 {
     if (KService::has('viewer')) {
         $query = $context->query;
         $repository = $query->getRepository();
         $viewer = get_viewer();
         if ($viewer->id) {
             $query->where("IF( FIND_IN_SET({$viewer->id}, @col(blockedIds)), 0, 1)");
         }
     }
 }
Пример #7
0
 /**
  * {@inheritdoc}
  */
 public function toSerializableArray($entity)
 {
     $data = new KConfig();
     $viewer = KService::has('com:people.viewer') ? KService::get('com:people.viewer') : null;
     $data[$entity->getIdentityProperty()] = $entity->getIdentityId();
     $data['objectType'] = 'com.' . $entity->getIdentifier()->package . '.' . $entity->getIdentifier()->name;
     if ($entity->isDescribable()) {
         $data['name'] = $entity->name;
         $data['body'] = $entity->body;
         $data['alias'] = $entity->alias;
     }
     if ($entity->inherits('ComBaseDomainEntityComment')) {
         $data['body'] = $entity->body;
     }
     if ($entity->isPortraitable()) {
         $imageURL = array();
         if ($entity->portraitSet()) {
             $sizes = $entity->getPortraitSizes();
             foreach ($sizes as $name => $size) {
                 $url = null;
                 if ($entity->portraitSet()) {
                     $url = $entity->getPortraitURL($name);
                 }
                 $parts = explode('x', $size);
                 $width = 0;
                 $height = 0;
                 if (count($parts) == 0) {
                     continue;
                 } elseif (count($parts) == 1) {
                     $height = $width = $parts[0];
                 } else {
                     $width = $parts[0];
                     $height = $parts[1];
                     //hack to set the ratio based on the original
                     if ($height == 'auto' && isset($sizes['original'])) {
                         $original_size = explode('x', $sizes['original']);
                         $height = $width * $original_size[1] / $original_size[0];
                     }
                 }
                 $imageURL[$name] = array('size' => array('width' => (int) $width, 'height' => (int) $height), 'url' => $url);
             }
         }
         $data['imageURL'] = $imageURL;
     }
     // @todo check for $entity->isAuthorizer() and $entity->authorize('administration') scenarios later on
     if ($entity->isAdministrable()) {
         $data['administratorIds'] = array_values($entity->administratorIds->toArray());
         if ($viewer) {
             $data['isAdministrated'] = $viewer->administrator($entity);
         }
     }
     if ($viewer && !$viewer->eql($entity)) {
         if ($entity->isFollowable()) {
             $data['isLeader'] = $viewer->following($entity);
         }
         if ($entity->isLeadable()) {
             $data['isFollower'] = $viewer->leading($entity);
         }
     }
     if ($entity->isModifiable() && !is_person($entity)) {
         $data->append(array('author' => null, 'creationTime' => null, 'editor' => null, 'updateTime' => null));
         if (isset($entity->author)) {
             $data['author'] = $entity->author->toSerializableArray();
             $data['creationTime'] = $entity->creationTime->getDate();
         }
         if (isset($entity->editor)) {
             $data['editor'] = $entity->editor->toSerializableArray();
             $data['updateTime'] = $entity->updateTime->getDate();
         }
     }
     if ($entity->isCommentable()) {
         $data['openToComment'] = (bool) $entity->openToComment;
         $data['numOfComments'] = $entity->numOfComments;
         $data['lastCommentTime'] = $entity->lastCommentTime ? $entity->lastCommentTime->getDate() : null;
         $data['lastComment'] = null;
         $data['lastCommenter'] = null;
         if (isset($entity->lastComment)) {
             $data['lastComment'] = $entity->lastComment->toSerializableArray();
         }
         if (isset($entity->lastCommenter)) {
             $data['lastCommenter'] = $entity->lastCommenter->toSerializableArray();
         }
     }
     if ($entity->isFollowable()) {
         $data['followerCount'] = $entity->followerCount;
     }
     if ($entity->isLeadable()) {
         $data['leaderCount'] = $entity->leaderCount;
         $data['mutualCount'] = $entity->mutualCount;
     }
     if ($entity->isSubscribable()) {
         $data['subscriberCount'] = $entity->subscriberCount;
     }
     if ($entity->isVotable()) {
         $data['voteUpCount'] = $entity->voteUpCount;
     }
     if ($entity->isOwnable()) {
         $data['owner'] = $entity->owner->toSerializableArray();
     }
     return KConfig::unbox($data);
 }
Пример #8
0
 /**
  * Before Update timestamp modified on and modifier
  *
  * @param KCommandContext $context Context parameter
  * 
  * @return void
  */
 protected function _beforeEntityUpdate(KCommandContext $context)
 {
     $entity = $context->entity;
     $modified = array_keys(KConfig::unbox($entity->getModifiedData()));
     $modified = count(array_intersect($this->_modifiable_properties, $modified)) > 0;
     if ($modified && KService::has('com:people.viewer')) {
         $entity->editor = get_viewer();
     }
 }
Пример #9
0
 function _initToolbar()
 {
     jimport('joomla.html.toolbar');
     require_once 'rttoolbar.class.php';
     if (KService::has('com:controller.toolbar')) {
         $toolbar = KService::get('com:controller.toolbar');
         JFactory::getDocument()->setBuffer($toolbar->getTitle(), 'modules', 'title');
         $bar = JToolBar::getInstance('toolbar');
         foreach ($toolbar->getCommands() as $command) {
             if (!$command->attribs->href) {
                 $command->attribs->href = '#';
             }
             $command->attribs->class = implode(" ", (array) KConfig::unbox($command->attribs->class));
             $command->attribs->class .= ' toolbar';
             $html = '<li>';
             $html .= '	<a ' . KHelperArray::toString($command->attribs) . '>';
             $html .= '		<span class="' . $command->icon . '" title="' . JText::_($command->title) . '"></span>';
             $html .= JText::_($command->label);
             $html .= '   </a>';
             $html .= '</li>';
             $bar->appendButton('custom', $html, $command->id);
         }
     } else {
         $bar = JToolBar::getInstance('toolbar');
     }
     $toolbar = $bar;
     $newbar = array();
     $newhelp = array();
     $actions = array();
     $first = array();
     foreach ($toolbar->_bar as $button) {
         if (strtolower($button[0]) == 'help') {
             // $newhelp[] = $button;
         } elseif (strtolower($button[1]) == 'unarchive' or strtolower($button[1]) == 'archive' or strtolower($button[1]) == 'publish' or strtolower($button[1]) == 'unpublish' or strtolower($button[1]) == 'move' or strtolower($button[1]) == 'copy' or strtolower($button[1]) == 'trash') {
             $actions[] = $button;
         } else {
             if (strtolower($button[1]) == 'new' or strtolower($button[1]) == 'apply' or strtolower($button[1]) == 'save') {
                 $first[] = $button;
             } else {
                 $newbar[] = $button;
             }
         }
     }
     //create new toolbar object
     $toolbar = new RTToolbar('toolbar');
     //$toolbar->_buttonPath[0] = $this->basePath.DS.'libraries'.DS.'joomla'.DS.'html'.DS.'toolbar'.DS.'button';
     $toolbar->_bar = $newbar;
     $toolbar->_buttonPath = $bar->_buttonPath;
     $toolbar->_actions = $actions;
     $toolbar->_first = $first;
     $this->toolbar = $toolbar;
     $this->actions = $actions;
     $this->first = $first;
     //new help button
     $helpbar = new RTToolbar('help');
     //$helpbar->_buttonPath[0] = $this->basePath.DS.'libraries'.DS.'joomla'.DS.'html'.DS.'toolbar'.DS.'button';
     $helpbar->_bar = $newhelp;
     $this->help = $helpbar;
 }
Пример #10
0
 /**
  * Helper mehtod to return a repository for an entity.
  *
  * @param string $identifier Entity Identifier
  * @param array  $config     Configuration
  *
  * @return AnDomainRepositoryAbstract
  */
 public static function getRepository($identifier, $config = array())
 {
     if (strpos($identifier, 'repos:') === 0) {
         $repository = KService::get($identifier);
     } else {
         $strIdentifier = (string) $identifier;
         if (!KService::has($identifier)) {
             $identifier = self::getEntityIdentifier($identifier);
         }
         if (!KService::has($identifier)) {
             KService::set($strIdentifier, KService::get($identifier, $config));
         }
         $repository = KService::get($identifier)->getRepository();
     }
     return $repository;
 }