public function actionSaveGoogleEvent($calendarId) { if (isset($_POST['EventId'])) { $eventId = $_POST['EventId']; $calendar = X2Calendar::model()->findByPk($calendarId); $googleCalendar = $calendar->getGoogleCalendar(); $googleEvent = $googleCalendar->events->get($calendar->googleCalendarId, $eventId); $model = new Actions(); foreach ($model->attributes as $field => $value) { if (isset($_POST['Actions'][$field])) { $model->{$field} = $_POST['Actions'][$field]; } } if ($model->allDay) { $googleEvent['start']['date'] = date('Y-m-d', Formatter::parseDateTime($model->dueDate)); if ($model->completeDate) { $googleEvent['end']['date'] = date('Y-m-d', Formatter::parseDateTime($model->completeDate) + 86400); } if (isset($googleEvent['start']['dateTime'])) { unset($googleEvent['start']['dateTime']); } if (isset($googleEvent['end']['dateTime'])) { unset($googleEvent['end']['dateTime']); } } else { $googleEvent['start']['dateTime'] = date('c', Formatter::parseDateTime($model->dueDate)); if ($model->completeDate) { $googleEvent['end']['dateTime'] = date('c', Formatter::parseDateTime($model->completeDate)); } if (isset($googleEvent['start']['date'])) { unset($googleEvent['start']['date']); } if (isset($googleEvent['end']['date'])) { unset($googleEvent['end']['date']); } } if ($model->color && $model->color != '#3366CC') { $colorTable = array(10 => 'Green', 11 => 'Red', 6 => 'Orange', 8 => 'Black'); if (($key = array_search($model->color, $colorTable)) != false) { $googleEvent['colorId'] = $key; } } $googleEvent = new Event($googleEvent); // we send back a proper Event object to google $googleEvent->setSummary($_POST['Actions']['actionDescription']); $googleCalendar->events->update($calendar->googleCalendarId, $eventId, $googleEvent); // $googleCalendar->events->delete($calendar->googleCalendarId, $eventId); } // $this->render('test', array('model'=>$_POST)); }
/** * Fixes up record association, parses dates (since this doesn't use * {@link X2Model::setX2Fields()}) * @return boolean whether or not to save */ public function beforeSave() { if ($this->scenario !== 'workflow') { $association = self::getAssociationModel($this->associationType, $this->associationId); if ($association === null) { $this->associationName = 'None'; $this->associationId = 0; } else { if ($association->hasAttribute('name')) { $this->associationName = $association->name; } if ($association->asa('X2TimestampBehavior') !== null) { if ($association->asa('changelog') !== null && Yii::app()->getSuName() == 'Guest') { $association->disableBehavior('changelog'); } $association->updateLastActivity(); $association->enableBehavior('changelog'); } } if ($this->associationName == 'None' && $this->associationType != 'none') { $this->associationName = ucfirst($this->associationType); } $this->dueDate = Formatter::parseDateTime($this->dueDate); $this->completeDate = Formatter::parseDateTime($this->completeDate); } // Whether this is a "timed" action record: $timed = $this->isTimedType; if (empty($timeSpent) && !empty($this->completeDate) && !empty($this->dueDate) && $timed) { $this->timeSpent = $this->completeDate - $this->dueDate; } return parent::beforeSave(); }
/** * Parses a value for table insertion using X2Fields rules * @param mixed $value * @param bool $filter If true, replace HTML special characters (prevents markup injection) * @return mixed the parsed value */ public function parseValue($value, $filter = false) { if (in_array($this->type, array('int', 'float', 'currency', 'percentage'))) { return self::strToNumeric($value, $this->type); } switch ($this->type) { case 'assignment': return $this->linkType === 'multiple' ? self::parseUsers($value) : $value; case 'date': case 'dateTime': if (is_numeric((string) $value)) { // must already be a timestamp return $value; } $value = $this->type === 'dateTime' ? Formatter::parseDateTime($value) : Formatter::parseDate($value); return $value === false ? null : $value; case 'link': if (empty($value) || empty($this->linkType)) { return $value; } list($name, $id) = self::nameAndId($value); if (ctype_digit((string) $id)) { // Already formatted as a proper reference. Check for existence of the record. $linkedModel = X2Model::model($this->linkType)->findByAttributes(array('nameId' => $value)); // Return the plain text name if the link is broken; otherwise, // given how the record exists, return the value. return empty($linkedModel) ? $name : $value; } else { if (ctype_digit($value)) { // User manually entered the ID, i.e. in an API call $link = Yii::app()->db->createCommand()->select('nameId')->from(X2Model::model($this->linkType)->tableName())->where('id=?', array($value))->queryScalar(); } else { // Look up model's unique nameId by its name: $link = Yii::app()->db->createCommand()->select('nameId')->from(X2Model::model($this->linkType)->tableName())->where('name=?', array($name))->queryScalar(); } } return $link === false ? $name : $link; case 'boolean': return (bool) $value; case 'text': return self::getPurifier()->purify($value); case 'dropdown': return is_array($value) ? CJSON::encode($value) : $value; default: return $filter ? CHtml::encode($value) : $value; } }
public static function parseValue($value, $type, &$params = null, $renderFlag = true) { if (is_string($value)) { if (strpos($value, '=') === 0) { // It's a formula. Evaluate it. $evald = X2FlowFormatter::parseFormula($value, $params); // Fail silently because there's not yet a good way of reporting // problems that occur in parseFormula -- $value = ''; if ($evald[0]) { $value = $evald[1]; } } else { // Run token replacement: $value = X2FlowFormatter::replaceVariables($value, $params, $type, $renderFlag, true); } } switch ($type) { case 'boolean': return (bool) $value; case 'time': case 'date': case 'dateTime': if (ctype_digit((string) $value)) { // must already be a timestamp return $value; } if ($type === 'date') { $value = Formatter::parseDate($value); } elseif ($type === 'dateTime') { $value = Formatter::parseDateTime($value); } else { $value = strtotime($value); } return $value === false ? null : $value; case 'link': $pieces = explode('_', $value); if (count($pieces) > 1) { return $pieces[0]; } return $value; case 'tags': return Tags::parseTags($value); default: return $value; } }
public function actionQuickUpdate($id) { $model = $this->loadModel($id); if (isset($_POST['Actions'])) { $model->setX2Fields($_POST['Actions']); $model->dueDate = Formatter::parseDateTime($model->dueDate); if ($model->completeDate) { $model->completeDate = Formatter::parseDateTime($model->completeDate); } elseif (empty($model->completeDate)) { $model->completeDate = $model->dueDate; } if ($model->save()) { $model->syncGoogleCalendar('update'); } if (isset($_POST['isEvent']) && $_POST['isEvent']) { // Update calendar event $event = X2Model::model('Events')->findByAttributes(array('associationType' => 'Actions', 'associationId' => $model->id)); if ($event !== null) { $event->timestamp = $model->dueDate; $event->update(array('timestamp')); } } } }
/** * The import assumes we have human readable data in the CSV and will thus need to convert. This * method converts link, date, and dateTime fields to the appropriate machine friendly data. * @param string $modelName The model class being imported * @param X2Model $model The currently importing model record * @param string $fieldName Field to set * @param string $importAttribute Value to set field * @returns X2Model $model */ protected function importRecordAttribute($modelName, X2Model $model, $fieldName, $importAttribute) { $fieldRecord = Fields::model()->findByAttributes(array('modelName' => $modelName, 'fieldName' => $fieldName)); // Skip setting the attribute if it has already been set or if the entry from // the CSV is empty. if (empty($importAttribute) && ($importAttribute !== 0 && $importAttribute !== '0')) { return $model; } if ($fieldName === 'actionDescription' && $modelName === 'Actions') { $text = new ActionText(); $text->text = $importAttribute; if (isset($model->id)) { $text->actionId = $model->id; } $this->setCurrentActionText($text->attributes); return $model; } // ensure the provided id is valid if (strtolower($fieldName) === 'id' && (!preg_match('/^\\d+$/', $importAttribute) || $importAttribute >= 4294967295)) { $model->id = $importAttribute; $model->addError('id', Yii::t('importexport', "ID '{$importAttribute}' is not valid.")); return $model; } switch ($fieldRecord->type) { case "link": $model = $this->importRecordLinkAttribute($modelName, $model, $fieldRecord, $importAttribute); break; case "dateTime": case "date": if (Formatter::parseDateTime($importAttribute) !== false) { $model->{$fieldName} = Formatter::parseDateTime($importAttribute); } break; case "visibility": switch ($importAttribute) { case 'Private': $model->{$fieldName} = 0; break; case 'Public': $model->{$fieldName} = 1; break; case 'User\'s Groups': $model->{$fieldName} = 2; break; default: $model->{$fieldName} = $importAttribute; } break; default: $model->{$fieldName} = $importAttribute; } return $model; }