public function run($id, $type, $getSub = false) { $controller = $this->getController(); $controller->title = "RESSOURCES"; $controller->subTitle = "Toutes les ressources de nos associations"; $controller->pageTitle = ucfirst($controller->module->id) . " - " . $controller->title; if ($type == Organization::COLLECTION) { $organizations = array(); $organization = Organization::getById($id); $organizations[$id] = $organization['name']; } $documents = Document::getWhere(array("type" => $type, "id" => $id, "contentKey" => array('$exists' => false))); if ($getSub && $type == Organization::COLLECTION && Authorisation::canEditMembersData($id)) { $subOrganization = Organization::getMembersByOrganizationId($id, Organization::COLLECTION); foreach ($subOrganization as $key => $value) { $organization = Organization::getById($key); $organizations[$key] = $organization['name']; $documents = array_merge($documents, Document::getWhere(array("type" => $type, "id" => $key, "contentKey" => array('$exists' => false)))); } } $categories = Document::getAvailableCategories($id, $type); $params = array("documents" => $documents, "id" => $id, "categories" => $categories, "organizations" => $organizations, "getSub" => $getSub); if (Yii::app()->request->isAjaxRequest) { echo $controller->renderPartial("documents", $params, true); } else { $controller->render("documents", $params); } }
/** * Return an array with the organizations the user is admin of * @param String the id of the user * @return array of Organization (organizationId => organizationValue) */ public static function listUserOrganizationAdmin($userId) { $res = array(); //organization i'am admin $where = array("links.members." . $userId . ".isAdmin" => true); $organizations = PHDB::find(Organization::COLLECTION, $where); $res = $organizations; foreach ($organizations as $e) { $res[(string) new MongoId($e['_id'])] = $e; if (Authorisation::canEditMembersData(new MongoId($e['_id']))) { if (isset($e["links"]["members"])) { foreach ($e["links"]["members"] as $key => $value) { if (isset($value["type"]) && $value["type"] == Organization::COLLECTION) { $subOrganization = Organization::getById($key); $res[$key] = $subOrganization; } } } } } return $res; }
public static function listEventsPublicAgenda($organizationId) { $events = array(); $organization = Organization::getById($organizationId); if (isset($organization["links"]["events"])) { foreach ($organization["links"]["events"] as $keyEv => $valueEv) { $event = Event::getPublicData($keyEv); $events[$keyEv] = $event; } } //Specific case : if canEditMember if (Authorisation::canEditMembersData($organizationId)) { $subOrganization = Organization::getMembersByOrganizationId($organizationId, Organization::COLLECTION); foreach ($subOrganization as $key => $value) { $newOrganization = Organization::getById($key); if (!empty($newOrganization) && isset($newOrganization["links"]["events"])) { foreach ($newOrganization["links"]["events"] as $keyEv => $valueEv) { $event = Event::getPublicData($keyEv); $events[$keyEv] = $event; } } } } foreach ($events as $key => $value) { $profil = Document::getLastImageByKey($key, PHType::TYPE_EVENTS, Document::IMG_PROFIL); if ($profil != "") { $value['imagePath'] = $profil; } } return $events; }
/** * Retrieve the list of events, the organization is organizer * Special case : when the organization can edit member data : retireve the events of the members * The event should not be over * The event of the organization $organizationId will be selected first * @param String $organizationId The organization Id * @param int $limit limit of the result * @return array list of the events the organization is part of the organization sorted on endDate */ public static function getListCurrentEventsByOrganizationId($organizationId, $limit = 20) { $listEvent = array(); $where = array('$and' => array(array("links.organizer." . $organizationId => array('$exists' => true)), array("endDate" => array('$gte' => new MongoDate(time()))))); $eventOrganization = PHDB::findAndSort(self::COLLECTION, $where, array('endDate' => 1), $limit); //If not enougth events, lets see for canEditMember if (count($eventOrganization) < $limit) { if (Authorisation::canEditMembersData($organizationId)) { $subOrganization = Organization::getMembersByOrganizationId($organizationId, Organization::COLLECTION); foreach ($subOrganization as $key => $value) { //Recursive call : yes papa !!! $subOrgaEvents = self::getListCurrentEventsByOrganizationId($key, $limit - count($eventOrganization)); foreach ($subOrgaEvents as $keyEvent => $valueEvent) { $eventOrganization[$keyEvent] = $valueEvent; } if (count($eventOrganization) >= $limit) { break; } } } } return Event::addInfoEvents($eventOrganization); }