/**
  * This function will return paginated result. Result is an array where first element is
  * array of returned object and second populated pagination object that can be used for
  * obtaining and rendering pagination data using various helpers.
  *
  * Items and pagination array vars are indexed with 0 for items and 1 for pagination
  * because you can't use associative indexing with list() construct
  *
  * @access public
  * @param array $arguments Query argumens (@see find()) Limit and offset are ignored!
  * @param integer $items_per_page Number of items per page
  * @param integer $current_page Current page number
  * @return array
  */
 function paginate($arguments = null, $items_per_page = 10, $current_page = 1)
 {
     if (isset($this) && instance_of($this, 'TemplateTasks')) {
         return parent::paginate($arguments, $items_per_page, $current_page);
     } else {
         return TemplateTasks::instance()->paginate($arguments, $items_per_page, $current_page);
     }
     // if
 }
Example #2
0
/**
 * Return true if $user can add an object of type $object_type_id in $member. False otherwise.
 *
 * @param Contact $user
 * @param Member $member
 * @param array $context_members
 * @param $object_type_id
 * @return boolean
 */
function can_add_to_member(Contact $user, $member, $context_members, $object_type_id, $check_dimension = true)
{
    if (TemplateTasks::instance()->getObjectTypeId() == $object_type_id) {
        $object_type_id = ProjectTasks::instance()->getObjectTypeId();
    }
    if (TemplateMilestones::instance()->getObjectTypeId() == $object_type_id) {
        $object_type_id = ProjectMilestones::instance()->getObjectTypeId();
    }
    if (!$member instanceof Member && is_array($member) && isset($member['id'])) {
        $member = Members::findById($member['id']);
    }
    if ($user->isGuest() || !$member || !$member->canContainObject($object_type_id)) {
        return false;
    }
    try {
        $contact_pg_ids = ContactPermissionGroups::getPermissionGroupIdsByContactCSV($user->getId(), false);
        if ($check_dimension) {
            $dimension = $member->getDimension();
        }
        //dimension does not define permissions - user can freely add in all members
        if ($check_dimension && !$dimension->getDefinesPermissions()) {
            return true;
        }
        //dimension defines permissions and user has maximum level of permissions so can freely in all members
        if ($check_dimension && $dimension->hasAllowAllForContact($contact_pg_ids)) {
            return true;
        }
        //check
        if (ContactMemberPermissions::contactCanReadObjectTypeinMember($contact_pg_ids, $member->getId(), $object_type_id, true, false, $user)) {
            $max_role_ot_perm = MaxRoleObjectTypePermissions::instance()->findOne(array('conditions' => "object_type_id='{$object_type_id}' AND role_id = '" . $user->getUserType() . "'"));
            // if user max permission cannot write this object type then return false
            if ($max_role_ot_perm && $max_role_ot_perm->getCanWrite()) {
                return true;
            } else {
                return false;
            }
        }
        //check for context permissions that allow user to add in this member
        if ($context_members) {
            $member_ids = array();
            foreach ($context_members as $member_obj) {
                $member_ids[] = $member_obj->getId();
            }
            $allowed_members = ContactMemberPermissions::getActiveContextPermissions($user, $object_type_id, $context_members, $member_ids, true);
            if (in_array($member, $allowed_members)) {
                return true;
            }
        }
    } catch (Exception $e) {
        tpl_assign('error', $e);
        return false;
    }
    return false;
}
 function canAdd(Contact $user, $context, &$notAllowedMember = '')
 {
     return can_add($user, $context, TemplateTasks::instance()->getObjectTypeId(), $notAllowedMember);
 }
 /**
  * Return manager instance
  *
  * @access protected
  * @param void
  * @return TemplateTasks
  */
 function manager()
 {
     if (!$this->manager instanceof TemplateTasks) {
         $this->manager = TemplateTasks::instance();
     }
     return $this->manager;
 }