/** * setup form * * * @uses \ReflectionClass * @uses Inflector * * @access public * @param string $name ,default is null * @param array $options ,default is null */ public function __construct($name = null, $options = null) { if (is_null($name)) { $reflection = new \ReflectionClass($this); $inflector = new Inflector(); $name = $inflector->underscore($reflection->getShortName()); } $auth = new AuthenticationService(); $storage = $auth->getIdentity(); if ($auth->hasIdentity() && in_array(Role::ADMIN_ROLE, $storage['roles'])) { $this->isAdminUser = true; } parent::__construct($name, $options); }
/** * Recursive menu items by parents branch extrusion * * @access public * @param array $menuItemsByParents * @param array $menuItemsPerParent * @param bool $treeFlag ,default is false * @param int $depthLevel ,default is 0 * * @return array parent children with children appended under it */ public function sortMenuItemsByParents(&$menuItemsByParents, &$menuItemsPerParent, $treeFlag = false, $depthLevel = 0) { $tree = array(); foreach ($menuItemsPerParent as $menuItem) { $menuItem->children = array(); if (isset($menuItemsByParents[$menuItem->getId()])) { $depthLevel++; // get all children under menu item $menuItem->children = $this->sortMenuItemsByParents($menuItemsByParents, $menuItemsByParents[$menuItem->getId()], $treeFlag, $depthLevel); $depthLevel--; } if ($treeFlag === false) { $tree[] = $menuItem; // append children under direct parent if (count($menuItem->children) > 0) { $tree = array_merge($tree, $menuItem->children); unset($menuItem->children); } } else { $menuItemTitle = $menuItem->getTitle(); $menuTitle = $this->inflector->underscore($menuItem->getMenu()->getTitle()); if ($menuItem->getType() == MenuItemEntity::TYPE_PAGE && is_object($menuItem->getPage())) { $path = $menuItem->getPage()->getPath(); } else { $path = $menuItem->getDirectUrl(); } $menuItemArray = array('depth' => $depthLevel, 'path' => $path, 'weight' => $menuItem->getWeight(), 'title_underscored' => $this->inflector->underscore($menuItemTitle), 'children' => $menuItem->children); $tree[$menuTitle][$menuItemTitle] = $menuItemArray; } } return $tree; }
/** * Load user fixture * * @access public * @param ObjectManager $manager */ public function load(ObjectManager $manager) { $faker = \Faker\Factory::create(); $userCredentials = UserCredentials::$userCredentials; $inflector = new Inflector(); foreach ($userCredentials as $userName => $userCredential) { $user = new UserEntity(); $date = new \DateTime(); $user->setFirstName($faker->firstName)->setMiddleName($faker->firstName)->setLastName($faker->lastName)->setCountry($faker->countryCode)->setLanguage($faker->languageCode)->setUsername($userName)->setPassword(UserEntity::hashPassword($userCredential["password"]))->setMobile($faker->numberBetween(1000000000, 2000000000))->setAddressOne($faker->address)->setAddressTwo($faker->address)->setCity($faker->city)->setZipCode($faker->postcode)->setPhone($faker->numberBetween(1000000000, 2000000000))->setNationality($faker->countryCode)->setIdentificationType($faker->word)->setIdentificationNumber($faker->numberBetween(999999))->setIdentificationExpiryDate($faker->dateTimeBetween('+2 years', '+20 years')->format(Time::DATE_FORMAT))->setEmail($faker->freeEmail)->setSecurityQuestion($faker->sentence)->setSecurityAnswer($faker->sentence)->setDateOfBirth($date->format(Time::DATE_FORMAT))->setPhoto('/upload/images/userdefault.png')->setPrivacyStatement(true)->setStatus(Status::STATUS_ACTIVE)->setStudentStatement(Status::STATUS_INACTIVE)->setInstructorStatement(Status::STATUS_INACTIVE)->setProctorStatement(Status::STATUS_INACTIVE)->setTestCenterAdministratorStatement(Status::STATUS_INACTIVE)->setTrainingManagerStatement(Status::STATUS_INACTIVE); $approvedStatementMethod = "set" . $inflector->camelize("{$userName}Statement"); if (method_exists($user, $approvedStatementMethod)) { $user->{$approvedStatementMethod}(Status::STATUS_ACTIVE); } $manager->persist($user); $this->addReference($userName . "User", $user); } $manager->flush(); }
/** * Get roles agreements status * * * @access public * @return array agreement status per each role */ public function getRolesAgreementsStatus() { $inflector = new Inflector(); $roles = $this->getRolesNames(); $rolesAgreementsStatus = array(); foreach ($roles as $role) { $roleAgrementStatusMethod = "get" . $inflector->camelize($role) . "Statement"; if (method_exists($this, $roleAgrementStatusMethod)) { $rolesAgreementsStatus[$role] = $this->{$roleAgrementStatusMethod}(); } } return $rolesAgreementsStatus; }