Contact AISC


dbh->prepare( $sql ); if ( $stmt->execute( array( $data ) ) ) { $results = $stmt->fetchAll(); if ( !empty( $results ) ) { if ( $multiple ) { $seen = array(); $employees = array(); foreach ( $results as $row ) { if ( !array_key_exists( $row['id'], $seen ) ) { $seen[ $row['id'] ] = 1; $employee = new self( $row, $core ); array_push( $employees, $employee ); } } return $employees; } else { return new self( $results[0], $core ); } } } return false; } /** * Gets the property out of the data array, or creates it based on certain parameters * * @since 1.1 * @param String The property to retrieve */ public function __get( $property ) { if ( !empty( $this->data[ $property ] ) ) { return trim( $this->data[ $property ] ); } else { switch ( (string) $property ) { case 'email': return $this->username . "@uw.edu"; break; case 'mailto': return "" . $this->email . ""; break; case 'name': return $this->firstname . " " . $this->lastname; default: return false; } } } /** * Checks if employee is in database. * * @param username The NetID of the employee * @return boolean Returns true if the user is in the database * * @since 1.0 */ public static function is_valid_username( $username ) { $core = new Core; $sql = "SELECT count(*) as count FROM employees WHERE username = ?"; $stmt = $core->dbh->prepare( $sql ); if ( $stmt->execute( array( $username ) ) ) { $row = $stmt->fetch(); return $row["count"] > 0; } return false; } /** * Gets the options for the dropdown menu built for WordPress shortcodes. * * @return array The methods that can be used. * * @since 1.0 */ public static function get_employee_options() { return array( "name", "title", "mailto", "username", "office", "entity", ); } } ?> employees = Employee::instance( "entity_id", $row["id"] ); parent::__construct( $row, $core ); return $this; } /** * Gets an array of all entities. This function is meant to replace get_all. * * @return array An array of all entities. * @since 1.1 */ public static function instance( $selector, $data = "", $core = false ) { $core = new Core; $sql = "SELECT * FROM contact.entities "; $multiple = true; switch ( (string) $selector ) { case "abbr": $multiple = false; $sql .= "WHERE abbr = ? "; break; case "all": break; default: return false; } $sql .= "ORDER BY name ASC"; $stmt = $core->dbh->prepare( $sql ); if( $stmt->execute( array( $data ) ) ) { $results = $stmt->fetchAll(); if( !empty($results) ) { if( $multiple ) { $entities = array(); foreach( $results as $row ) { $entity = new self( $row, $core ); array_push( $entities, $entity ); } return $entities; } else { return new self( $results[0], $core ); } } } return false; } /** * Gets any data from the entity, including some custom options (mailto, etc.) * * @param property The property of the entity to get. * * @return mixed The value of whatever is requested. * * @since 1.1 */ public function __get( $property ) { switch ( (string) $property ) { case 'phone': $one = substr( $this->data["phone"], 0, 3 ); $two = substr( $this->data["phone"], 3, 3 ); $three = substr( $this->data["phone"], 6, 4 ); return $one . "-" . $two . "-" . $three; break; case 'name': case 'abbr': case 'email': return htmlspecialchars( $this->data[ $property ] ); break; case 'facebook': return "//facebook.com/" . $this->data[ $property ]; break; case 'twitter': return "//twitter.com/" . $this->data[ $property ]; break; case 'mailto': return "" . $this->email . ""; break; } if ( !empty( $this->data[ $property ] ) ) { return $this->data[ $property ]; } else { return false; } } /** * Gets an options list of publically available data about an entity. * * @return String[] An array of fields available */ public static function get_entity_options() { return array( "name", "office", "phone", "email", "facebook", "twitter", ); } } ?>