Пример #1
0
 /**
  * Constructor.
  *
  * @param KConfig $config An optional KConfig object with configuration options.
  *
  * @return void
  */
 public function __construct(KConfig $config)
 {
     if (!$config->actor) {
         throw new KException('Actor object is missing');
     }
     $this->_actor = $config->actor;
     parent::__construct($config);
     $query = $this->getService($config->repository)->getQuery()->bind('actorid', $this->_actor->id)->bind('components_set_to_never', $this->getService('repos://site/components.assignment')->getQuery()->columns('id')->where('@col(actortype) = :actortype AND @col(access) = :never'))->bind('actortype', (string) $this->_actor->getEntityDescription()->getInheritanceColumnValue()->getIdentifier())->bind('never', ComComponentsDomainBehaviorAssignable::ACCESS_NEVER)->bind('always', ComComponentsDomainBehaviorAssignable::ACCESS_ALWAYS)->bind('optional', ComComponentsDomainBehaviorAssignable::ACCESS_OPTIONAL);
     $query->link('repos://site/components.assignment', '@col(assignment.component) = @col(component)', array('type' => 'weak'))->enabled(true)->where('@col(id) NOT IN (:components_set_to_never)');
     if ($config->can_enable) {
         $query->where('@col(assignment.actortype) = :actortype AND @col(access) = :optional');
     } else {
         $query->where('((@col(assignment.actortype) = :actortype AND @col(access) = :always) OR @col(assignment.actor.id)  = :actorid OR @col(option) = "com_stories")');
     }
     $config['query'] = $query;
     $this->_object = $this->getService('anahita:domain.entityset', KConfig::unbox($config));
 }
Пример #2
0
 /**
  * Adds a condition for list of components that are assigned to actor
  * 
  * @param ComActorsDomainEntityActor $actor
  * 
  * @return ComComponentsDomainQueryComponent
  */
 public function assignedToActor($actor)
 {
     $actortype = $actor->getEntityDescription()->getInheritanceColumnValue()->getIdentifier();
     $this->where('assignments.actor', '=', $actor)->where('(@col(assignments.actortype) = @quote(' . $actortype . ') AND @col(assignments.access IN (2,1) ))', 'OR');
     return $this;
 }
Пример #3
0
 /**
  * Checks an array of permissions against an accessor using the socialgraph between the
  * accessor and actor.
  * 
  * @param ComActorsDomainEntityActor $actor       The actor who's trying to perform an operation
  * @param array                      $permissions An array of permissions
  * @param ComActorsDomainEntityActor $owner       If one of the permision
  * 
  * @return bool
  */
 public function checkPermissions($actor, $permissions, $owner)
 {
     $result = true;
     //all must be false in order to return false
     foreach ($permissions as $value) {
         $value = pick($value, self::GUEST);
         switch ($value) {
             //public
             case self::GUEST:
                 $result = true;
                 break;
                 //registered
             //registered
             case self::REG:
                 $result = !$actor->guest();
                 break;
                 //follower
             //follower
             case self::FOLLOWER:
                 $result = $actor->following($owner) || $actor->leading($owner) || $actor->administrator($owner);
                 break;
                 //leader
             //leader
             case self::LEADER:
                 $result = $actor->leading($owner) || $actor->administrator($owner);
                 break;
                 //mutual
             //mutual
             case self::MUTUAL:
                 $result = $actor->mutuallyLeading($owner) || $actor->administrator($owner);
                 break;
             case self::ADMIN:
                 $result = $actor->administrator($owner);
                 break;
             default:
                 $result = $actor->id == $value;
         }
         if ($result === true) {
             break;
         }
     }
     return $result;
 }
Пример #4
0
 /**
  * Lead a person command.
  *
  * @param ComActorsDomainEntityActor  $actor  that is going to be followed
  * @param ComPeopleDomainEntityPerson $person person that is going to be added as a follower to the $actor
  *
  * @return LibBaseTemplateObject
  */
 public function getLeadCommand($actor, $person)
 {
     if (!$actor->isFollowable() || !$person->isLeadable()) {
         return;
     }
     if ($actor->eql($person)) {
         return;
     }
     if ($actor->blocking($person)) {
         return;
     }
     if ($person->following($actor) && $actor->authorize('administration')) {
         $command = $this->getCommand('lead', array('receiver' => $person, 'actor' => $actor, 'action' => 'unlead'));
         $command->name = 'unlead';
     } elseif (!$person->following($actor) && $actor->authorize('lead')) {
         $command = $this->getCommand('lead', array('receiver' => $person, 'actor' => $actor, 'action' => 'lead'));
         $command->name = 'lead';
     } else {
         return;
     }
     return $command;
 }
Пример #5
0
 /**
  * Return whether the component is active for actor. A component is active, if
  * it has been assigned as awlays for the actor type or it has been enabled for the
  * actor.
  *
  * @param ComActorsDomainEntityActor $actor The actor object
  *
  * @return bool
  */
 public function activeForActor($actor)
 {
     $actortype = $actor->getEntityDescription()->getInheritanceColumnValue()->getIdentifier();
     $access = $this->getAssignmentForIdentifier($actortype);
     $return = false;
     if ($access == self::ACCESS_ALWAYS) {
         $return = true;
     } elseif ($access == self::ACCESS_OPTIONAL) {
         $return = $this->enabledForActor($actor);
     }
     return $return;
 }
Пример #6
0
 /**
  * Captures the password value when password is set through
  * magic methods
  * 
  * @{inheritdoc}
  */
 public function __set($key, $value)
 {
     if ($key == 'password' && !empty($value)) {
         $this->setPassword($value);
     } else {
         return parent::__set($key, $value);
     }
 }
Пример #7
0
 /**
  * Draws an actor cover image
  * 
  * @param ComActorsDomainEntityActor $actor
  * @param string                    $size 
  * @param boolean                   $linked if true it returns a linked image tag of not just an image tag
  * @param array                     $attr link attributes
  * 
  * @return string
  */
 public function cover($actor, $size = 'large', $linked = true, $attr = array())
 {
     if (is_numeric($size)) {
         $width = "width=\"{$size}\"";
         $size = 'large';
     } else {
         $width = '';
     }
     if ($actor->coverSet()) {
         $src = $actor->getCoverURL($size);
         $name = KHelperString::ucwords($actor->name);
         $img = '<img ' . $width . ' alt="' . $name . '" class="cover" src="' . $src . '"  />';
     }
     if ($linked && $actor->authorize('access')) {
         $url = $this->getActorURL($actor);
         $img = '<a ' . $this->_buildAttribute($attr) . ' data-actor="' . $actor->id . '" href="' . $url . '" >' . $img . '</a>';
     }
     return $img;
 }
Пример #8
0
 /**
  * Adds an $person to a list of blocked actors
  * 
  * @param ComActorsDomainEntityActor $person
  * 
  * @return void
  */
 public function addBlocked($person)
 {
     //if A blocks B, then A must remove B as a follower
     //need to keep track of this since the mixin is a singleton
     $leader = $this->_mixer;
     $person->removeFollower($leader);
     $leader->removeFollower($person);
     //just in case
     $person->removeRequester($leader);
     $leader->removeRequester($person);
     $edge = $this->getService('repos:actors.block')->findOrAddNew(array('blocker' => $leader, 'blocked' => $person));
     $edge->save();
     $this->resetStats(array($leader, $person));
     return $edge;
 }