Last active
August 29, 2015 14:09
-
-
Save timkelty/09b42e50105b6c420c5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Craft; | |
class Recurly_PlanModel extends BaseModel | |
{ | |
protected function defineAttributes() { | |
return array( | |
'sortOrder' => AttributeType::SortOrder, | |
'code' => AttributeType::String, | |
'max' => AttributeType::Number, | |
'min' => AttributeType::Number, | |
'baseEndpoints' => AttributeType::Number, | |
'endpointCost' => AttributeType::String, | |
'annual' => array('type' => AttributeType::Bool, 'default' => false), | |
'baseCost' => array('type' => AttributeType::Number, 'decimals' => 2), | |
'endpointCost' => array('type' => AttributeType::Number, 'decimals' => 2), | |
); | |
} | |
protected function getAnnualSavings() { | |
return $this->annual ? $this->baseCost + $endpointCost * $baseEndpoints : 0; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function actionGetPlans() | |
{ | |
$plans = craft()->recurly->getPlans(); | |
$this->returnJson($plans); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function getPlans() | |
{ | |
$records = Recurly_PlanRecord::model()->findAll(); | |
$models = Recurly_PlanModel::PopulateModels($records); | |
return $models; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So with this, I can do
$model->annualSavings
to get exactly what I want, but since it isn't defined as attribute, I don't get it in$this->returnJson($plans)
.