PHP User::fromArray Examples

PHP User::fromArray - 13 examples found. These are the top rated real world PHP examples of User::fromArray extracted from open source projects. You can rate examples to help us improve the quality of examples.
 /**
  * Returns an Assistant object based on the Array inputs. calls the parent (User) fromArray method to setup the User fields
  * @param array $arr
  * @return Assistant
  */
 public static function fromArray(array $arr)
 {
     $asst = new self();
     $asst = parent::fromArray($arr, $asst);
     $asst->addAssistantFields($arr);
     return $asst;
 }
    public function testFromArrayRecord()
    {
        $user = new User();
        $userArray = $user->toArray();

        # add a Phonenumber
        $userArray['Phonenumber'][0]['phonenumber'] = '555 321';
        
        # add an Email address
        $userArray['Email']['address'] = 'johndow@mail.com';
        
        # add group
        $userArray['Group'][0]['name'] = 'New Group'; # This is a n-m relationship
        # add a group which exists
        $userArray['Group'][1]['_identifier'] = $this->previous_group; # This is a n-m relationship where the group was made in prepareData
          
        $user->fromArray($userArray);
        
        $this->assertEqual($user->Phonenumber->count(), 1);
        $this->assertEqual($user->Phonenumber[0]->phonenumber, '555 321');
        $this->assertEqual($user->Group[0]->name, 'New Group');
        $this->assertEqual($user->Group[1]->name, 'Group One');
        
        try {
          $user->save();
        } catch (Exception $e ) {
          $this->fail("Failed saving with " . $e->getMessage());
        }
    }
 /**
  * Alias for User::fromArray()
  * @see User::fromArray()
  * @param array $arr
  * @return ClinicalFacultyMember
  */
 public static function fromArray(array $arr)
 {
     $user = new self();
     //to ensure the object is of the correct type
     $user = parent::fromArray($arr, $user);
     return $user;
 }
 /**
  * Returns a Collection of User objects 
  * TODO add criteria to selection process 
  * @param array
  * @return Users
  */
 public static function get($organisation = null, $group = null, $role = null, $proxy_id = null)
 {
     global $db;
     $query = "SELECT a.*, b.`group`, b.`role`, b.`id` AS `access_id` from `" . AUTH_DATABASE . "`.`user_data` a LEFT JOIN `" . AUTH_DATABASE . "`.`user_access` b on a.`id`=b.`user_id` and b.`app_id`=?";
     $conditions = generateAccessConditions($organisation, $group, $role, $proxy_id, 'b');
     if ($conditions) {
         $query .= " WHERE " . $conditions;
     }
     $query .= " ORDER BY lastname, firstname";
     //note to self. check use index page for user access components of display
     $results = $db->getAll($query, array(AUTH_APP_ID));
     $users = array();
     if ($results) {
         foreach ($results as $result) {
             $user = new User();
             $user = User::fromArray($result, $user);
             $cohort = groups_get_cohort($result["id"]);
             if ($cohort) {
                 $user->setCohort($cohort["group_id"]);
             }
             $users[] = $user;
         }
     }
     return new self($users);
 }
Example #5
0
 public static function getByName($name)
 {
     $db = Connection::getConnection();
     $obj = new User();
     $stmt = $db->prepare("SELECT * FROM {$obj->tableName} WHERE userName = :name");
     $stmt->bindParam('name', $name);
     $stmt->execute();
     $row = $stmt->fetch(PDO::FETCH_ASSOC);
     if (!$row) {
         return null;
     }
     $obj->fromArray($row);
     return $obj;
 }
 /**
  * Returns a collection of User objects belonging to the provided cohort
  * <code>
  * $class = Cohort::get(2014);
  * foreach ($class as $student) { ... }
  * </code>
  * 
  * @param int $cohort
  * @return Cohort
  */
 public static function get($cohort)
 {
     global $db;
     $query = "SELECT * FROM `" . AUTH_DATABASE . "`.`user_data` AS a \n\t\t\t\tJOIN `group_members` AS b \n\t\t\t\tON a.`id` = b.`proxy_id`\n\t\t\t\tWHERE b.`group_id` = " . $db->qstr($cohort);
     $results = $db->getAll($query);
     $users = array();
     if ($results) {
         foreach ($results as $result) {
             $user = new User();
             $user = User::fromArray($result, $user);
             $users[] = $user;
         }
     }
     return new self($users, $cohort);
 }
 /**
  * 
  * @param int $year
  * @return MSPRs
  */
 public static function getYear($year)
 {
     global $db, $ORGANISATION_ID;
     $query = "SELECT * \n                    FROM `student_mspr` AS a\n                    JOIN `" . AUTH_DATABASE . "`.`user_data` AS b\n                    ON a.`user_id` = b.`id`\n                    JOIN `" . AUTH_DATABASE . "`.`user_access` AS c\n                    ON b.`id` = c.`user_id`\n                    WHERE c.`group` = 'student'\n                    AND c.`organisation_id` = " . $db->qstr($ORGANISATION_ID) . "\n                    AND (c.`role` = " . $db->qstr($year) . " OR b.`grad_year` = " . $db->qstr($year) . ")\n                    GROUP BY a.`user_id`";
     $results = $db->GetAll($query);
     $msprs = array();
     if ($results) {
         foreach ($results as $result) {
             $user = new User();
             $user = User::fromArray($result, $user);
             $mspr = MSPR::fromArray($result);
             $msprs[] = $mspr;
         }
     }
     return new self($msprs);
 }
 public function testFromArray()
 {
     $user = new User();
     $userArray = array('Group' => array($this->group_two, $this->group_three));
     $user->fromArray($userArray);
     $this->assertEqual($user->Group[0]->name, 'Group Two');
     $this->assertEqual($user->Group[1]->name, 'Group Three');
 }
Example #9
0
 public static function getIndividualMembers($proxy_id = null)
 {
     global $db;
     $member = false;
     $query = "\tSELECT a.`id` AS `user_id`, a.`number`, a.`firstname`, a.`lastname`,\n                    a.`username`, a.`email`, a.`organisation_id`, b.`group`, b.`role`\n                    FROM `" . AUTH_DATABASE . "`.`user_data` AS a\n                    LEFT JOIN `" . AUTH_DATABASE . "`.`user_access` AS b\n                    ON a.`id` = b.`user_id`\n                    WHERE b.`app_id` IN (" . AUTH_APP_IDS_STRING . ")\n                    AND b.`account_active` = 'true'\n                    AND (b.`access_starts` = '0' OR b.`access_starts` <= ?)\n                    AND (b.`access_expires` = '0' OR b.`access_expires` > ?)\n                    AND a.`id` = ?\n                    GROUP BY a.`id`\n                    ORDER BY a.`lastname` ASC, a.`firstname` ASC";
     $result = $db->GetRow($query, array(time(), time(), $proxy_id));
     if ($result) {
         $m = new User();
         $member = User::fromArray($result, $m);
     }
     return $member;
 }
Example #10
0
 /**
  * Updates a user
  *
  * @param int $intId The user ID
  * @param array $arrData The data array
  * @throws Exception
  * @return int The user ID
  */
 public function do_update($intId = null, $arrData)
 {
     $user = null;
     $con = Propel::getConnection();
     if (!$con->beginTransaction()) {
         throw new Exception('Could not start transaction.');
     }
     try {
         $authUser = $this->requireUser();
         $accountId = $authUser->getAccountId();
         $validator = new KickstartValidator();
         $locale = Localizer::getInstance();
         if ($intId and (!isset($arrData['Password']) or $arrData['Password'] == '')) {
             unset($this->filter_basic['Password']);
             unset($arrData['Password']);
             unset($arrData['Password2']);
         }
         $warnings = $validator->filterErrors($arrData, $this->initFilter($this->filter_basic, $locale));
         if ($warnings) {
             return array('result' => false, 'warnings' => $warnings);
         }
         if ($intId) {
             $user = $authUser->getSubordinate($intId);
         } else {
             $user = new User();
             $user->setAccountId($accountId)->setDomainId($authUser->getDomainId());
         }
         if (isset($arrData['Password'])) {
             $user->setPassword($arrData['Password']);
         }
         $allowedFields = array('Name' => true, 'Firstname' => true, 'Lastname' => true, 'Phone' => true, 'Email' => true, 'Number' => true);
         if ($authUser->getIsAdmin()) {
             $allowedFields += array('DomainId' => true, 'ManagerOf' => true, 'IsAdmin' => true);
         }
         $user->fromArray(array_intersect_key($arrData, $allowedFields));
         // Fail if domain does not belong to authenticated account
         $domain = $user->getDomain($con);
         if ($domain === null or $domain->getAccountId() !== $accountId) {
             throw new Exception('Invalid domain ID #' . $user->getDomainId());
         }
         $user->save($con);
         if (!empty($arrData['Properties'])) {
             $user->setProperties($arrData['Properties'], $con);
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
     if (!$con->commit()) {
         throw new Exception('Could not commit transaction.');
     }
     return $user->getId();
 }
Example #11
0
<?php

require 'vendor/autoload.php';
Struct\Struct::$strict = false;
struct('User', ['name' => 'string', 'age' => 'int', 'active' => 'bool']);
$user = new User();
$user->fromArray(array('name' => 'George', 'age' => 36, 'extradata' => 'thisthat', 'active' => false));
struct('User', ['firstName' => 'string', 'lastName' => 'string', 'active' => 'bool', 'age' => 'int'], ['fullName' => function () {
    return $this['firstName'] . ' ' . $this['lastName'];
}, 'birthYear' => function () {
    $year = date('Y') - $this['age'];
    return $year;
}, '__toString' => function () {
    return $this->fullName() . ' is a ' . $this['age'] . ' year old ' . ($this['active'] ? 'active' : 'inactive') . ' user';
}]);
$user = new User();
echo $user;
Example #12
0
define('SITE_PATH', realpath(dirname(__FILE__)) . DIRSEP);
define('MODELS_PATH', SITE_PATH . "models" . DIRSEP);
define('MODULES_PATH', SITE_PATH . "modules" . DIRSEP);
define('TMPL_PATH', SITE_PATH . "views" . DIRSEP);
require SITE_PATH . "startup.php";
$smarty = new Smarty();
$smarty->compile_check = true;
$smarty->debugging = false;
$registry->set('smarty', $smarty);
$template = new Template($registry);
$registry->set('template', $template);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
try {
    $db_link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
    mysqli_set_charset($db_link, "UTF8");
    $registry->set('dl', $db_link);
} catch (Exception $ex) {
    $registry->set('dl', null);
}
$router = new Router($registry);
$registry->set('router', $router);
$user = new User();
if (isset($_SESSION['user'])) {
    $user->fromArray($_SESSION['user']);
}
$registry->set('user', $user);
$router->setPath(SITE_PATH . 'controllers');
$router->getController($file, $controller, $action, $args);
$registry->set("controller", array("file" => $file, "controller" => $controller, "action" => $action, "args" => $args));
$smarty->assign("controller", $registry->get("controller"));
$router->delegate();
Example #13
0
 public function getTeachersByDates($event_start = null, $event_finish = null)
 {
     global $db;
     $teachers = false;
     $query = "  SELECT a.`event_id`, b.*, c.`firstname`, c.`lastname`, c.`email` FROM `events` AS a \n                    JOIN `event_contacts` AS b\n                    ON a.`event_id` = b.`event_id`\n                    LEFT JOIN `entrada_auth`.`user_data` AS c\n                    ON b.`proxy_id` = c.`id`\n                    WHERE a.`course_id` = ? \n                    AND a.`event_start` >= ?\n                    AND a.`event_finish` <= ?\n                    AND b.`contact_role` = ?\n                    GROUP BY b.`proxy_id`";
     $results = $db->GetAll($query, array($this->course_id, $event_start, $event_finish, "teacher"));
     if ($results) {
         foreach ($results as $result) {
             $teacher = new User();
             $teachers[] = $teacher->fromArray($result, $teacher);
         }
     }
     return $teachers;
 }