00001 <?php
00002
00020 class TSDStandardOrganization extends TSDObject {
00021 public static $ATTRIBUTES = array(
00022 'id' => false,
00023 'name' => 'edit',
00024 'url' => 'edit',
00025 'state' => 'edit',
00026 'address' => 'edit',
00027 'description' => 'edit'
00028 );
00029
00036 public function __construct($id = '') {
00037 parent::__construct('TSDOrganization', self::$ATTRIBUTES, 'id', $id);
00038 }
00039
00048 public function isValid() {
00049 return (
00050 ($this->id == '' || ctype_digit((string) $this->id)) &&
00051 (is_string($this->name) && $this->name != '') &&
00052 (is_string($this->url) || $this->url == '') &&
00053 (is_string($this->state) || $this->state== '') &&
00054 (is_string($this->address) || $this->address == '') &&
00055 (is_string($this->description) || $this->description == '')
00056 );
00057 }
00058
00074 public static function getList($constraints = array(), $limit = array(), $order = array(), $cnt = false) {
00075 return self::getListImpl('TSDStandardOrganization', 'TSDOrganization', array_keys(self::$ATTRIBUTES),
00076 $constraints, array(), $limit, $order, $cnt);
00077 }
00078
00087 public function getParent() {
00088 return null;
00089 }
00090
00098 public function getIdentifier() {
00099 return $this->name;
00100 }
00101
00118 public function listChildren($constraints = array(), $limit = array(), $order = array(), $cnt = false) {
00119 return self::getListImpl('TSDStandardGrade', 'TSDGrade', array_keys(TSDStandardGrade::$ATTRIBUTES),
00120 $constraints, array('organizationId' => $this->id), $limit, $order, $cnt);
00121 }
00122
00142 public function listValidChildren($constraints = array(), $limit = array(), $order = array(), $cnt = false) {
00143 $ljoin = 'LEFT JOIN TSDGrade ON TSDGrade.organizationId = TSDOrganization.id
00144 LEFT JOIN TSDCategory ON TSDCategory.gradeId = TSDGrade.id
00145 LEFT JOIN TSDObjective ON TSDObjective.categoryId = TSDCategory.id';
00146 return self::getListImpl('TSDStandardGrade', 'TSDGrade', null, $constraints,
00147 array('gradeId' => $this->id, 'IS NOT NULL', 'TSDObjective.id' => 0),
00148 $limit, $order, $cnt, $ljoin);
00149 }
00150
00158 public function addGrade($name) {
00159 if(!$this->checkInit('Cannot add grades')) return null;
00160 if(!TSD::can('edit')) {
00161 $this->setError('Permission denied');
00162 return false;
00163 }
00164
00165 $grade = new TSDStandardGrade();
00166 $grade->setAttr('name', $name);
00167 $grade->setAttr('organizationId', $this->id);
00168 if(!$grade->commit())
00169 return null;
00170
00171 return $grade;
00172 }
00173
00181 public function deleteGradeByName($name) {
00182 if(!$this->checkInit('Cannot delete grade(s)')) return null;
00183 if(!TSD::can('edit')) {
00184 $this->setError('Permission denied');
00185 return false;
00186 }
00187
00188 $grade = $this->listGrades(array('name' => $name));
00189 foreach($grade as $g)
00190 if(!$g->delete())
00191 return false;
00192 return true;
00193 }
00194 }
00195
00196 ?>