Beispiel #1
0
 /**
  * Watches config for this entity's custom fields, if any key value pair matches 
  * a custom field name, it is extracted from the values and added to a new value with key
  * 'custom_fields'
  * 
  * @param \EntityPopulator\Entities\Entity $entity The Redmine entity being created 
  * treated.
  * 
  * @return void
  */
 public static function adaptCustomFields(Entity $entity)
 {
     $customFields = $entity->getCustomFieldsConfig();
     $fields = $entity->toArray();
     $usedCustomFields = array_intersect_key($fields, $customFields);
     if (0 < count($usedCustomFields)) {
         $apiReadyCustomFields = self::createCustomFields($entity, $usedCustomFields);
         $nativeFields = array_diff_key($fields, $customFields);
         $nativeFields += $apiReadyCustomFields;
         $entity->fromArray($nativeFields);
     }
 }
Beispiel #2
0
 /**
  * Generate the setter and getter method PHPDoc declaration to paste into your entity class.
  *
  * @param Entity $entity
  */
 public static function makeSetterGetterDoc(Entity $entity)
 {
     $properties = $entity->toArray(false);
     $entityName = $entity->calledClassName();
     echo "<pre>\n";
     foreach ($properties as $name => $value) {
         $methodName = ucfirst($name);
         $type = $entity->typeof($name);
         echo " * @method {$entityName} set{$methodName}({$type} \$value)\n";
         echo " * @method {$type} get{$methodName}()\n";
     }
     echo "</pre>\n";
 }
Beispiel #3
0
 /**
  * @param Entity $entity
  * @return int Returns the number of rows affected by the query 
  */
 public function update(Entity $entity)
 {
     $vars = $entity->toArray();
     unset($vars['id'], $vars['created_at']);
     if (array_key_exists('updated_at', $vars)) {
         $vars['updated_at'] = date('Y-m-d H:i:s');
         $entity->addUpdated('updated_at');
     }
     $updatedColumns = $entity->getUpdated();
     if (count($updatedColumns) <= 0) {
         return false;
     }
     $entity->resetUpdated();
     $columns = '';
     $values = array();
     foreach ($updatedColumns as $column) {
         $columns .= '`' . $column . '` = ?,';
         $values[] = $vars[$column];
     }
     $sql = 'UPDATE ' . $this->table . ' SET ' . rtrim($columns, ',') . ' WHERE id = ' . $entity->id;
     $stmt = $this->execute($sql, $values);
     return $stmt instanceof PDOStatement ? $stmt->rowCount() : false;
 }
Beispiel #4
0
 public function toArray()
 {
     $result = parent::toArray();
     $result['content'] = Utility::DecodeAsSafeString($result['content']);
     return $result;
 }
Beispiel #5
0
 /**
  * Returns [$sector, $rank] (both strings) of the sector that an
  * answer is about and the rank the respondent gave to it.
  *
  * @param array $answer Answer array
  * @param Entity $survey The result of a call to SurveysTable::get()
  * @return array [$sector, $rank]
  */
 public function decodeAnswer($answer, $survey)
 {
     $answerIds = $survey->toArray();
     $sectorId = $answer['row'];
     $sector = str_replace('_aid', '', array_search($sectorId, $answerIds));
     $rankId = $answer['col'];
     $rank = str_replace('_aid', '', array_search($rankId, $answerIds));
     return [$sector, $rank];
 }
 /**
  * Update an existing user.
  *
  * @param  \Stidges\LaravelDbNormalizer\Entity  $user
  * @return bool
  */
 public function update(Entity $user)
 {
     $model = $this->model->newInstance($user->toArray(), true);
     $model->id = $user->id;
     return $user->getDirtyAttributes() ? $model->save() : $model->touch();
 }
 /**
  * Update an existing user.
  *
  * @param  \Stidges\LaravelDbNormalizer\Entity  $user
  * @return bool
  */
 public function update(Entity $user)
 {
     $data = array_only($user->toArray(), $this->fillable);
     return (bool) $this->db->table($this->table)->where('id', $user->id)->update($data);
 }
Beispiel #8
0
 public function toArray()
 {
     $attribute_values = parent::toArray();
     $attribute_values[self::OBJECT_TYPE] = $this->getType()->getVariantPrefix();
     return $attribute_values;
 }